Skip to content

Instantly share code, notes, and snippets.

@kent013
Created March 5, 2012 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kent013/1977237 to your computer and use it in GitHub Desktop.
Save kent013/1977237 to your computer and use it in GitHub Desktop.
Converting Resources/*.lproj/Localizable.strings to one combined strings.txt
<?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