From adde93d2e2b0e38de01ad6ca07458fb3a405f356 Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Fri, 29 Jun 2012 13:58:35 +0000 Subject: scripts to manage localized strings --- tools/extract2lang.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/pa2lang.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 tools/extract2lang.php create mode 100644 tools/pa2lang.php diff --git a/tools/extract2lang.php b/tools/extract2lang.php new file mode 100644 index 000000000..8d3a05188 --- /dev/null +++ b/tools/extract2lang.php @@ -0,0 +1,100 @@ + $strs) { + $f = array(); + $f[] = sprintf('# Generated by extract2lang.php on %s', date('c')); + $f[] = sprintf('# Domain %s', $domain); + + foreach ($strs as $str => $info) { + $str = str_replace(array("\'", "\""), array("'", '"'), $str); + $f[] = ''; + $f[] = sprintf('# %s', $info[0]); + $f[] = ';' . $str; + $f[] = $str; + $f[] = ''; + } + $f = implode("\n", $f); + $dest = sprintf('%s/langs/%s/%s.%s.lang', APP_ROOT, 'en', $domain, 'en'); + $dir = dirname($dest); + + if (!is_dir($dir)) { + echo "making $dir\n"; + mkdir($dir, 0755, true); + } + echo sprintf("saved %d strings in %s\n", count($strs), $dest); + if (FALSE === file_put_contents($dest, $f)) + echo "Failed to write.\n"; +} +echo "Done. kthxbye.\n"; +exit(0); diff --git a/tools/pa2lang.php b/tools/pa2lang.php new file mode 100644 index 000000000..8c28d3960 --- /dev/null +++ b/tools/pa2lang.php @@ -0,0 +1,100 @@ + $v) { + + echo sprintf("> %s has %d strings.", $k, count($v)); + + $f = array(); + $f[] = sprintf('# Generated by pa2lang.php on %s', date('c')); + $f[] = sprintf('# from %s $%s', $php_source, $var); + + foreach ($v as $s0 => $s1) { + $s0 = str_replace("\n", ' ', $s0); + + if (is_array($s1)) { + echo "\nWe have an array for string $k:'$s0':\n"; + foreach ($s1 as $sv) + echo " * ", $sv, "\n"; + + echo "\nThis can't be inserted into this .lang file. Fix this upstream and come back.\n\n"; + exit(1); + } + $s1 = str_replace("\n", ' ', $s1); + + $f[] = ''; + $f[] = ';' . $s0; + $f[] = $s1; + $f[] = "\n"; + } + + echo " ok\n"; + $files[$k] = implode("\n", $f); +} + +echo "Saving those into ...\n"; +foreach ($files as $k => $data) { + $file = str_replace('{LOC}', $k, $dest); +// file_put_contents($file, $data); +} + +echo "Done.\n"; +exit(0); \ No newline at end of file -- cgit v1.2.1