Last active
March 1, 2018 12:22
-
-
Save twesolowski/14bb2bf3e00872915a03 to your computer and use it in GitHub Desktop.
Prestashop country translation importer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* example usage: php parse.php --file="de\data\country.xml" --lang=de --prefix=ps_ | |
* generates imports country translations in DE lang | |
*/ | |
$options = getopt(null, array( | |
"file:", // Required | |
"prefix::", // Optional | |
"lang::" // Required | |
)); | |
$file = isset($options['file']) or die("No file"); | |
$lang = isset($options['lang']) or die("No lang"); | |
$file = $options['file']; | |
$lang = $options['lang']; | |
$prefix = isset($options['prefix']) ? $options['prefix'] : "ps_"; | |
file_exists($file) or die("File $file doesn't exist"); | |
$xml=simplexml_load_file($file) or die("Error: Cannot create object"); | |
//var_dump($xml); | |
foreach($xml as $element){ | |
echo 'REPLACE INTO '.$prefix.'country_lang SET id_country= (SELECT id_country FROM '.$prefix.'country WHERE iso_code="'.$element->attributes()->id.'"), id_lang=(SELECT id_lang FROM '.$prefix.'lang WHERE iso_code="'.$lang.'"), name="'.$element->name.'"; '; | |
echo "\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment