Created
March 5, 2012 07:26
-
-
Save kent013/1977237 to your computer and use it in GitHub Desktop.
Converting Resources/*.lproj/Localizable.strings to one combined strings.txt
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 | |
$ens = file_get_contents("tottepost/en.lproj/Localizable.strings"); | |
$jas = file_get_contents("tottepost/ja.lproj/Localizable.strings"); | |
$ens = mb_convert_encoding($ens, "utf-8", "utf-16"); | |
//$jas = mb_convert_encoding($jas, "utf-8", "utf-16"); | |
$ens = explode("\n", $ens); | |
$jas = explode("\n", $jas); | |
$strings = array(); | |
foreach($ens as $en){ | |
if(preg_match('/"([^"]+?)" *= *"([^"]+?)";/u', $en, $regs)){ | |
$strings[$regs[1]]["en"] = $regs[2]; | |
} | |
} | |
foreach($jas as $ja){ | |
if(preg_match('/"([^"]+?)" *= *"([^"]+?)";/u', $ja, $regs)){ | |
$strings[$regs[1]]["ja"] = $regs[2]; | |
} | |
} | |
$output = array("[[General]]"); | |
foreach($strings as $k => $s){ | |
if(isset($s["en"]) == false || empty($s["en"]) || empty($s["ja"])){ | |
die("$k has empty record\n"); | |
} | |
$output[] = " [$k]"; | |
if(preg_match('/AAM/', $k)){ | |
$output[] = " tags = common, aam_feedback"; | |
}else{ | |
$output[] = " tags = common"; | |
} | |
$output[] = " en = " . $s["en"]; | |
$output[] = " ja = " . $s["ja"]; | |
} | |
$output = implode("\n", $output) . "\n"; | |
echo $output; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment