| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
$locale = dirname(__FILE__) . '/MacUploadr.app/Contents/Resources/chrome/locale'; |
|---|
| 6 |
|
|---|
| 7 |
if (count($_GET)){ |
|---|
| 8 |
$argv = array_keys($_GET); |
|---|
| 9 |
array_unshift($argv, 'foo.php'); |
|---|
| 10 |
} |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
if (!isset($argv[1])) { |
|---|
| 15 |
die("Usage: $argv[0] <intl-directory>\n"); |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
foreach (array('de-de', 'es-us', 'fr-fr', 'it-it', 'ko-kr', 'pt-br', 'zh-hk') as $l) { |
|---|
| 20 |
$dir = opendir("$argv[1]/$l"); |
|---|
| 21 |
if (!$dir) die; |
|---|
| 22 |
while (false !== $file = readdir($dir)) { |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
if (0 == preg_match('/^.*ext_uploadr3_(.*\.(?:dtd|properties)).txt.php$/', $file, $match)) { |
|---|
| 26 |
continue; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
if (!file_exists("$locale/$l") && !mkdir("$locale/$l", 0755)) { |
|---|
| 31 |
echo "[error] Can't create locale $l\n"; |
|---|
| 32 |
continue; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
$text = file_get_contents("$argv[1]/$l/$file"); |
|---|
| 37 |
if (false === $text) { |
|---|
| 38 |
echo "[error] Reading $file\n"; |
|---|
| 39 |
continue; |
|---|
| 40 |
} |
|---|
| 41 |
$text = trim(preg_replace('/^<\?php.*\?>$/ms', '', $text)); |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
$lines = explode("\n", $text); |
|---|
| 45 |
$ii = sizeof($lines); |
|---|
| 46 |
$replace = array(); |
|---|
| 47 |
for ($i = 0; $i < $ii; ++$i) { |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
if (preg_match('/^(<!ENTITY [a-zA-Z0-9.]+ ")(.+)(">)$/', $lines[$i], $s)) { |
|---|
| 51 |
$lines[$i] = $s[1] . str_replace('"', '"', |
|---|
| 52 |
preg_replace('/&(?!#\d\d;)/', '&', $s[2])) . $s[3]; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
if (preg_match('/^<!ENTITY ([a-zA-Z0-9.]+) "(.+)">$/', $lines[$i], $s) |
|---|
| 57 |
&& preg_match('/^(.+)\.joined$/', $s[1], $k)) { |
|---|
| 58 |
$parts = explode(' ', $s[2]); |
|---|
| 59 |
if (2 == sizeof($parts)) { |
|---|
| 60 |
$replace["{$k[1]}.1"] = "{$parts[0]} "; |
|---|
| 61 |
$replace["{$k[1]}.2"] = " {$parts[1]}"; |
|---|
| 62 |
$lines[$i] = ''; |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
for ($i = 0; $i < $ii; ++$i) { |
|---|
| 70 |
if (preg_match('/^<!ENTITY ([a-zA-Z0-9.]+) ".+">$/', $lines[$i], $s) |
|---|
| 71 |
&& isset($replace[$s[1]])) { |
|---|
| 72 |
$lines[$i] = "<!ENTITY {$s[1]} \"{$replace[$s[1]]}\">"; |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
$file = next($match); |
|---|
| 78 |
$file_p = fopen("$locale/$l/$file", 'w'); |
|---|
| 79 |
if (false === $file_p) { |
|---|
| 80 |
echo "[error] Opening $file\n"; |
|---|
| 81 |
continue; |
|---|
| 82 |
} |
|---|
| 83 |
if (false === fwrite($file_p, implode("\n", $lines))) { |
|---|
| 84 |
echo "[error] Writing $file\n"; |
|---|
| 85 |
} |
|---|
| 86 |
if (false === fclose($file_p)) { |
|---|
| 87 |
echo "[error] Closing $file\n"; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
echo "[ok] finished writing $l/$file\n"; |
|---|
| 91 |
} |
|---|
| 92 |
closedir($dir); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
?> |
|---|