1 #!/usr/local/bin/php -q
4 /* Reminder: always indent with 4 spaces (no tabs). */
5 // +---------------------------------------------------------------------------+
7 // +---------------------------------------------------------------------------+
10 // | Update a language file by merging it with english.php |
11 // +---------------------------------------------------------------------------+
12 // | Copyright (C) 2004-2009 by the following authors: |
14 // | Author: Dirk Haun - dirk AT haun-online DOT de |
15 // +---------------------------------------------------------------------------+
17 // | This program is free software; you can redistribute it and/or |
18 // | modify it under the terms of the GNU General Public License |
19 // | as published by the Free Software Foundation; either version 2 |
20 // | of the License, or (at your option) any later version. |
22 // | This program is distributed in the hope that it will be useful, |
23 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 // | GNU General Public License for more details. |
27 // | You should have received a copy of the GNU General Public License |
28 // | along with this program; if not, write to the Free Software Foundation, |
29 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
31 // +---------------------------------------------------------------------------+
35 // Prevent PHP from reporting uninitialized variables
36 error_reporting( E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR );
38 // name of the language file should be passed on the command line
39 $langfile = $GLOBALS['argv'][1];
40 if (empty ($langfile)) {
41 echo "lm.php v{$VERSION}\n";
42 echo "This is free software; see the source for copying conditions.\n\n";
43 echo "Usage: {$GLOBALS['argv'][0]} langfile.php [module] > new-langfile.php\n\n";
48 if (!empty($GLOBALS['argv'][2])) {
49 $module = $GLOBALS['argv'][2];
53 if (strpos($filename, '_utf-8') !== false) {
56 if (!function_exists('mb_strpos')) {
57 echo "Sorry, this script needs a PHP version that has multibyte support compiled in.\n\n";
59 } elseif (!function_exists('mb_ereg_replace')) {
60 echo "Sorry, this script needs a PHP version with the mb_ereg_replace function compiled in.\n\n";
64 mb_regex_encoding('UTF-8');
65 mb_internal_encoding('UTF-8');
70 // list of all variables accessed in the language file
71 $_DB_mysqldump_path = '{$_DB_mysqldump_path}';
72 $_CONF['backup_path'] = '{$_CONF[\'backup_path\']}';
73 $_CONF['commentspeedlimit'] = '{$_CONF[\'commentspeedlimit\']}';
74 $_CONF['site_admin_url'] = '{$_CONF[\'site_admin_url\']}';
75 $_CONF['site_name'] = '{$_CONF[\'site_name\']}';
76 $_CONF['site_url'] = '{$_CONF[\'site_url\']}';
77 $_CONF['speedlimit'] = '{$_CONF[\'speedlimit\']}';
78 $_USER['username'] = '{$_USER[\'username\']}';
80 $failures = '{$failures}';
82 $fromemail = '{$fromemail}';
84 $shortmsg = '{$shortmsg}';
85 $successes = '{$successes}';
89 // load the English language file
91 require_once 'language/english.php';
92 } elseif ($module == 'install') {
93 require_once 'public_html/admin/install/language/english.php';
95 require_once 'plugins/' . $module . '/language/english.php';
98 $lastp = strrpos($_SERVER['PHP_SELF'], DIRECTORY_SEPARATOR);
99 if ($lastp === false) {
100 $incpath = '.' . DIRECTORY_SEPARATOR;
102 $incpath = substr($_SERVER['PHP_SELF'], 0, $lastp + 1);
104 $incpath .= 'include' . DIRECTORY_SEPARATOR;
108 echo "###############################################################################\n";
111 function separatorThin()
113 echo "// +---------------------------------------------------------------------------+\n";
117 * My mb-save replacement for some(!) string replacements
120 function my_str_replace($s1, $s2, $s3)
125 return mb_ereg_replace($s1, $s2, $s3);
127 return str_replace($s1, $s2, $s3);
132 * My mb-save replacement for some(!) use cases of strpos
135 function my_strpos($s1, $s2)
140 return mb_strpos($s1, $s2);
142 return strpos($s1, $s2);
147 * Make <br> and <hr> tags XHTML compliant
150 function makeXHTML($txt)
154 // fix accidentally created <brXHTML> tags in some 1.5.0b1 language files
155 $txt = my_str_replace('brXHTML', 'br', $txt);
158 $fc = mb_substr($txt, 0, 1);
160 $fc = substr($txt, 0, 1);
163 $txt = my_str_replace('<br>',
164 '<br' . $fc . ' . XHTML . ' . $fc . '>', $txt);
165 $txt = my_str_replace('<hr>',
166 '<hr' . $fc . ' . XHTML . ' . $fc . '>', $txt);
171 function prepareText($newtxt)
175 if (my_strpos($newtxt, '{$') === false) {
176 if (my_strpos($newtxt, '\n') === false) {
177 // text contains neither variables nor line feeds,
178 // so enclose it in single quotes
179 $newtxt = my_str_replace("'", "\'", $newtxt);
180 $quotedtext = "'" . $newtxt . "'";
182 // text contains line feeds - enclose in double quotes so
183 // they can be interpreted
184 $newtxt = my_str_replace('"', '\"', $newtxt);
185 $quotedtext = '"' . $newtxt . '"';
188 // text contains variables
190 $newtxt = mb_ereg_replace('\$', '\$', $newtxt);
192 $newtxt = mb_ereg_replace('\{\\\\\$', '{$', $newtxt);
193 $newtxt = mb_ereg_replace('"', '\"', $newtxt);
195 $newtxt = str_replace('$', '\$', $newtxt);
196 $newtxt = str_replace('{\$', '{$', $newtxt);
197 $newtxt = str_replace('"', '\"', $newtxt);
199 $quotedtext = '"' . $newtxt . '"';
206 * Merge two language arrays
208 * This function does all the work. Any missing text strings are copied
209 * over from english.php. Also does some pretty-printing.
212 function mergeArrays($ENG, $OTHER, $arrayName, $comment = '')
216 $numElements = sizeof($ENG);
219 if ($comment !== false) {
222 if (!empty ($comment)) {
223 $comments = explode ("\n", $comment);
224 foreach ($comments as $c) {
228 echo "\n\${$arrayName} = array(\n";
230 foreach ($ENG as $key => $txt) {
232 if (is_numeric($key)) {
238 if (empty($OTHER[$key])) {
239 // string does not exist in other language - use English text
242 if (isset($ENG[$key]) && empty($ENG[$key])) {
243 // string is now empty in English language file - remove it
246 // string exists in other language - keep it
247 $newtxt = $OTHER[$key];
251 if (!is_array($newtxt)) {
252 $newtxt = my_str_replace("\n", '\n', $newtxt);
255 if (is_array($newtxt)) { // mainly for the config selects
256 $quotedtext = 'array(';
257 foreach ($newtxt as $nkey => $ntxt) {
258 $quotedtext .= "'" . my_str_replace("'", "\'", $nkey) . "' => ";
259 if ($ntxt === true) {
260 $quotedtext .= 'true';
261 } elseif ($ntxt === false) {
262 $quotedtext .= 'false';
263 } elseif (is_numeric($ntxt)) {
264 $quotedtext .= $ntxt;
266 $quotedtext .= "'" . my_str_replace("'", "\'", $ntxt) . "'";
271 $quotedtext = mb_substr($quotedtext, 0, -2);
273 $quotedtext = substr($quotedtext, 0, -2);
277 // hack for this special case ...
278 if ($quotedtext == "array('True' => 1, 'False' => '')") {
279 $quotedtext = "array('True' => TRUE, 'False' => FALSE)";
282 // ??? $quotedtext = mb_ereg_replace("\n", '\n', $quotedtext);
284 $quotedtext = prepareText($newtxt);
287 $quotedtext = makeXHTML($quotedtext);
289 if ($counter != $numElements) {
292 echo "$quotedtext\n";
295 if ($comment === false) {
302 function mergeString($eng, $other, $name)
312 $quotedtext = prepareText($newtxt);
313 $quotedtext = makeXHTML($quotedtext);
315 echo "\$$name = $quotedtext;\n";
319 * Read the credits / copyright from the other language file.
320 * Assumes that it starts and ends with a separator line of # signs.
323 function readCredits($langfile)
327 $firstcomment = false;
329 $fh = fopen ($langfile, 'r');
335 if (strstr ($line, '#####') !== false) {
336 // end of credits reached
338 } elseif (strstr($line, '*/') !== false) {
339 // end of credits reached, Spam-X style
341 } elseif (strstr($line, '+-----') !== false) {
342 $nextline = fgets($fh);
343 $tst = trim($nextline);
345 // end of credits reached, install script style
348 $credits[] = $nextline;
352 if (strstr ($line, '#####') !== false) {
354 $firstcomment = true;
356 } elseif (strstr($line, '/**') !== false) {
357 // start of credits, Spam-X style
358 $firstcomment = true;
360 } elseif (strstr($line, '/* Reminder:') !== false) {
361 // start of credits, install script style
362 $firstcomment = true;
376 $credits = readCredits($langfile);
378 // output starts here ...
382 foreach ($credits as $c) {
383 echo "$c"; // Note: linefeeds are part of the credits
386 // load the module file which does the rest
388 if (empty($module)) {
389 require_once $incpath . 'core.inc';
391 require_once $incpath . $module . '.inc';