From 49336cac86eda54a418f035a2c7184f3f76a4e90 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 16 May 2018 17:39:03 +0200 Subject: [PATCH] generate_lang_file.php : Add output file feature --- public_html/lang/generate_lang_file.php | 35 ++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/public_html/lang/generate_lang_file.php b/public_html/lang/generate_lang_file.php index 3f9244bf..ad93296f 100755 --- a/public_html/lang/generate_lang_file.php +++ b/public_html/lang/generate_lang_file.php @@ -33,6 +33,7 @@ require_once('conf/config.inc.php'); $withoutselectlist=False; $copyoriginalvalue=False; $interactive=False; +$output=False; $additionalfileformat=False; $lang=False; $encoding=False; @@ -70,6 +71,10 @@ if ($argc > 1) { die("Invalid --lang parameter. Must be compose in format : [lang].[encoding]\n"); } } + elseif($argv[$i]=='--output' || $argv[$i]=='-o') { + $i++; + $output = $argv[$i]; + } elseif($argv[$i]=='-h') { echo "Usage : ".$argv[0]." [file1] [file2] [-h] [options]\n"; echo " --without-select-list Don't add possibles values of select list\n"; @@ -77,6 +82,7 @@ if ($argc > 1) { echo " -i/--interactive Interactive mode : ask user to enter translated on each translation needed\n"; echo " --additional-file-format Additional file format output\n"; echo " --lang Load this specify lang (format : [lang].[encoding])\n"; + echo " -o/--output Output file (default : stdout)\n"; exit(0); } } @@ -401,9 +407,25 @@ find_and_parse_addon_file(LS_LOCAL_DIR.LS_ADDONS_DIR); ksort($data); -echo "getMessage(), "\n"); + } + if (!$fd) { + fwrite(STDERR, "Use stdout out instead.\n"); + $fd = STDOUT; + $output = false; + } +} +else + $fd = STDOUT; -if (!$additionalfileformat) print "\$GLOBALS['LSlang'] = array (\n"; +fwrite($fd, " $val) { if ($copyoriginalvalue && $val=="") { @@ -412,13 +434,14 @@ foreach($data as $key => $val) { $key=str_replace('"','\\"',$key); $val=str_replace('"','\\"',$val); if ($additionalfileformat) { - print "\$GLOBALS['LSlang'][\"$key\"] = \"$val\";\n"; + fwrite($fd, "\$GLOBALS['LSlang'][\"$key\"] = \"$val\";\n"); } else { - print "\n\"$key\" =>\n \"$val\",\n"; + fwrite($fd, "\n\"$key\" =>\n \"$val\",\n"); } } -if (!$additionalfileformat) echo "\n);\n"; +if (!$additionalfileformat) fwrite($fd, "\n);\n"); -?> +if ($output) + fclose($fd);