Last active
December 13, 2017 17:27
-
-
Save spinsch/a675084384e47fba1340c41d8b6b51e1 to your computer and use it in GitHub Desktop.
convert magento translation-file to apple-ios string-file to use the google translation toolkit
This file contains hidden or 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 | |
/** | |
* convert magento translation file to ios STRING file | |
* to use the google translation toolkit | |
* | |
* usage: php convert.php translation.csv > translation.STRINGS | |
* php convert.php translation.STRINGS > translation.csv | |
* | |
* @author rcro <[email protected]> | |
*/ | |
if (!isset($argv[1]) OR !file_exists($argv[1])) { | |
echo "file not exists!\n"; | |
exit; | |
} | |
$way = strtolower(pathinfo($argv[1], PATHINFO_EXTENSION)); | |
if (!in_array($way, array('csv','strings'))) { | |
echo "filetype not support!\n"; | |
exit; | |
} | |
$handle = fopen($argv[1], "r"); | |
if (!$handle) { | |
echo "fopen exit!\n"; | |
exit; | |
} | |
$converter = '_'.$way; | |
while (($line = fgets($handle)) !== false) { | |
echo $converter($line)."\n"; | |
} | |
fclose($handle); | |
function _csv($str) | |
{ | |
$str = explode(",", trim($str)); | |
$str = $str[0]; | |
if (strlen($str) == 0) { | |
return ""; | |
} | |
if ($str[0] == '"') { | |
$str[0] = ""; | |
} | |
if ($str[strlen($str)-1] == '"') { | |
$str[strlen($str)-1] = ""; | |
} | |
$str = trim(str_replace(array('"', '='), array('\"', '%%'), $str)); | |
return '"'.$str.'"="'.$str.'";'; | |
} | |
function _strings($str) | |
{ | |
$str = trim($str); | |
if (strlen($str) == 0) { | |
return ""; | |
} | |
return str_replace(array('=', ';', '\"', '%%'), array(',', '', '"', '='), $str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment