diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/extract2lang.php | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/tools/extract2lang.php b/tools/extract2lang.php index 8593b8b1f..17d8417ff 100644 --- a/tools/extract2lang.php +++ b/tools/extract2lang.php @@ -7,6 +7,7 @@ * @license MIT * @author Romain d'Alverny, rdalverny, rda * @copyright 2012/05 + * @author Filip (small fixes and some added features) */ if (php_sapi_name() !== 'cli') { @@ -41,30 +42,22 @@ U; echo "ohai!\n"; -//$path = 'en/3/download_index.php en/for-pc/index.php en/for-server/index.php en/3/index.php en/3/nav.php'; -//$path = realpath(APP_ROOT . '/' . $path); -$path = $php_source; - -//$domain = '3'; - -$cmd = sprintf('grep -HrnEi "_(e|t|h|d)\((.*)" %s', $path); +$cmd = sprintf('grep -HrnEi "_(e|t|h|d)\((.*)" %s', $php_source); echo $cmd, "\n"; exec($cmd, $out); $strings = array(); +$f = array(); +$error = 0; foreach ($out as $str) { - $arr = explode(':', $str); - $file = array_shift($arr); - /* - $domain = trim(str_replace(array('/en/', APP_ROOT), '', dirname($file))); - if ($domain == '/en') - $domain = 'index'; - */ - $file = str_replace(APP_ROOT, '', $file); - $line = array_shift($arr); - $arr = implode(':', $arr); - $arr = str_replace('\\\'', '_apostrophe_', $arr); + $arr = explode(':', $str); + $file = array_shift($arr); + $file = str_replace(APP_ROOT, '', $file); + $files[] = $file; + $line = array_shift($arr); + $arr = implode(':', $arr); + $arr = str_replace('\\\'', '_apostrophe_', $arr); if (preg_match_all('/\_(e|t|h|d)\(\'(.+)\'/imU', $arr, $reg)) { foreach ($reg[2] as $found) { @@ -72,14 +65,21 @@ foreach ($out as $str) { $strings[$domain][$found][] = $file . ' +' . $line; } } - else - echo "!!!! could not find for $file, $line: $str\n"; + else { + echo "\n\n!!!! Could not find string in $file, line $line: $str\n"; + echo "!!!! Please fix $file before using $domain.en.lang file!!!\n\n"; + $error = 2; + } } foreach ($strings as $domain => $strs) { - $f = array(); - $f[] = sprintf('# Generated by extract2lang.php on %s', date('c')); - $f[] = sprintf('# Domain %s', $domain); + $f[] = sprintf('# Generated by extract2lang.php on %s', date('c')); + $f[] = sprintf('# Domain %s', $domain); + $f[] = '# include translation strings from:'; + $files = array_unique($files); + foreach ($files as $source) { + $f[] = sprintf('# %s', $source); + } foreach ($strs as $str => $info) { $str = str_replace(array("\'", "\""), array("'", '"'), $str); @@ -102,4 +102,4 @@ foreach ($strings as $domain => $strs) { echo "Failed to write.\n"; } echo "Done. kthxbye.\n"; -exit(0); +exit($error); |