aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lookup_for_second_argument.php
diff options
context:
space:
mode:
authorFilip Komar <filip@mageia.org>2014-03-01 18:15:17 +0000
committerFilip Komar <filip@mageia.org>2014-03-01 18:15:17 +0000
commitfea2eca9cb50ba0dd1058358bc0feb58304a3d80 (patch)
tree14473e0a8ed3499e559ff4e957a5ecdbf42dfa3a /tools/lookup_for_second_argument.php
parent1f3db960405e08e0f707a5de5810c3c12040709d (diff)
downloadwww-fea2eca9cb50ba0dd1058358bc0feb58304a3d80.tar
www-fea2eca9cb50ba0dd1058358bc0feb58304a3d80.tar.gz
www-fea2eca9cb50ba0dd1058358bc0feb58304a3d80.tar.bz2
www-fea2eca9cb50ba0dd1058358bc0feb58304a3d80.tar.xz
www-fea2eca9cb50ba0dd1058358bc0feb58304a3d80.zip
first step towards transition from lang files to gettext translation system
Diffstat (limited to 'tools/lookup_for_second_argument.php')
-rw-r--r--tools/lookup_for_second_argument.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/lookup_for_second_argument.php b/tools/lookup_for_second_argument.php
new file mode 100644
index 000000000..97ce33728
--- /dev/null
+++ b/tools/lookup_for_second_argument.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Lookup for second argument in functions _t() and _d() in source code
+ *
+ * PHP 5.3
+ *
+ * @license MIT
+ * @author Filip (transformation to build a gettext dictionary)
+ * @copyright 2014/02
+ * based on extract2lang.php by author Romain d'Alverny, rdalverny, rda
+*/
+
+if (php_sapi_name() !== 'cli') {
+ echo "CLI only.\n";
+ exit(1);
+}
+
+if (version_compare(PHP_VERSION, '5.3.0') < 0) {
+ echo "PHP 5.3 needed.\n";
+ exit(1);
+}
+
+$php_source = isset($argv[1]) ? $argv[1] : null;
+$domain = isset($argv[2]) ? $argv[2] : null;
+
+if (is_null($php_source) || is_null($domain)) {
+ echo <<<U
+Usage:
+ php tools/lookup_for_second_argument.php path/to/source.php domain_name
+
+ Example:
+ php tools/lookup_for_second_argument.php en/index.php index
+
+ You can join multiple sources with apostrophe - single quote (') like this:
+ 'en/3/download_index.php en/for-pc/index.php en/for-server/index.php en/3/index.php en/3/nav.php'
+
+U;
+ exit(1);
+}
+
+date_default_timezone_set(@date_default_timezone_get());
+
+$cmd = sprintf('grep -HrnEi "_(e|t|h|d)\((.*)" %s', $php_source);
+exec($cmd, $out);
+
+foreach ($out as $str) {
+ $arr = explode(':', $str);
+ $file = array_shift($arr);
+ $line = array_shift($arr);
+ $arr = implode(':', $arr);
+ $arr = str_replace('\\\'', '_apostrophe_', $arr);
+ if (preg_match_all('/\_(t|d)\(\'(.+)\'(,.+)$/im', $arr, $test)) { // qq i=PCRE_CASELESS, m=PCRE_MULTILINE, U=PCRE_UNGREEDY
+ foreach ($test[3] as $more_arg) { // qq
+ $att = $php_source . ' (line ' . $line . '): '. trim($arr) . PHP_EOL; // qq
+ $attention[] = $att;
+ echo $att . PHP_EOL;
+ }
+ }
+}
+
+exit(0);