aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2012-06-29 13:58:35 +0000
committerRomain d'Alverny <rda@mageia.org>2012-06-29 13:58:35 +0000
commitadde93d2e2b0e38de01ad6ca07458fb3a405f356 (patch)
tree978d050bf7e468b8a1939a296ae050a6cb96cf81 /tools
parent9f42aef1e5dd33a427b4ecdf3366caa33b0b84f5 (diff)
downloadwww-adde93d2e2b0e38de01ad6ca07458fb3a405f356.tar
www-adde93d2e2b0e38de01ad6ca07458fb3a405f356.tar.gz
www-adde93d2e2b0e38de01ad6ca07458fb3a405f356.tar.bz2
www-adde93d2e2b0e38de01ad6ca07458fb3a405f356.tar.xz
www-adde93d2e2b0e38de01ad6ca07458fb3a405f356.zip
scripts to manage localized strings
Diffstat (limited to 'tools')
-rw-r--r--tools/extract2lang.php100
-rw-r--r--tools/pa2lang.php100
2 files changed, 200 insertions, 0 deletions
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 @@
+<?php
+/**
+ * Lookup for _e(), _t() and _h() in source code and build a
+ *
+ * PHP 5.3
+ *
+ * @license MIT
+ * @author Romain d'Alverny, rdalverny, rda
+ * @copyright 2012/05
+*/
+
+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);
+}
+
+define('APP_ROOT', realpath(__DIR__ . '/..'));
+
+$php_source = isset($argv[1]) ? $argv[1] : null;
+$var = isset($argv[2]) ? $argv[2] : null;
+$domain = isset($argv[3]) ? $argv[3] : null;
+
+/*
+if (is_null($php_source) || is_null($var) || is_null($domain)) {
+ echo <<<U
+Usage:
+ pa2lang.php path/to/source.php var_name domain_name
+
+
+U;
+ exit(1);
+}
+*/
+
+echo "ohai!\n";
+
+$path = 'en/2/download_index.php en/for-pc/index.php en/for-server/index.php en/2/index.php';
+//$path = realpath(APP_ROOT . '/' . $path);
+
+$domain = '2';
+
+$cmd = sprintf('grep -HrnEi "_(e|t|h)\((.*)\)" %s', $path);
+echo $cmd, "\n";
+exec($cmd, $out);
+
+$strings = array();
+
+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);
+
+ if (preg_match_all('/\_(e|t|h)\(\'(.+)\'/imU', $arr, $reg)) {
+ foreach ($reg[2] as $found) {
+ $strings[$domain][$found][] = $file . ' +' . $line;
+ }
+ }
+ else
+ echo "!!!! could not find for $file, $line: $str\n";
+}
+
+foreach ($strings as $domain => $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 @@
+<?php
+/**
+ * Migrate PHP array to .lang files.
+ *
+ * PHP 5.3
+ *
+ * @license MIT
+ * @author Romain d'Alverny, rdalverny, rda
+ * @copyright 2012/05
+*/
+
+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);
+}
+
+define('APP_ROOT', realpath(__DIR__ . '/..'));
+
+$php_source = isset($argv[1]) ? $argv[1] : null;
+$var = isset($argv[2]) ? $argv[2] : null;
+$domain = isset($argv[3]) ? $argv[3] : null;
+
+if (is_null($php_source) || is_null($var) || is_null($domain)) {
+ echo <<<U
+Usage:
+ pa2lang.php path/to/source.php var_name domain_name
+
+
+U;
+ exit(1);
+}
+
+echo "ohai!\n";
+
+$dest = sprintf('%s/langs/{LOC}/%s.{LOC}.lang', APP_ROOT, $domain);
+
+$php_source = realpath(APP_ROOT . '/' . $php_source);
+if (is_null($php_source)) {
+ echo "$php_source is not found. kthxbye.\n";
+ exit(1);
+}
+
+echo "Loading ", $php_source, " looking for \$$var\n";
+
+include $php_source;
+
+if (!isset($$var)) {
+ echo "$var is not set. kthxbye\n";
+ exit(1);
+}
+
+echo sprintf("Found %d locales here: %s.\n",
+ count($$var), implode(', ', array_keys($$var)));
+
+$files = array();
+
+foreach ($$var as $k => $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