[geeklog-cvs] tools/lm README, 1.2, 1.3 lm.php, 1.2, 1.3 uplng.sh, 1.2, 1.3 mblm.php, 1.2, NONE
Dirk Haun
dhaun at qs1489.pair.com
Sun Apr 27 05:48:08 EDT 2008
Update of /cvsroot/geeklog/tools/lm
In directory qs1489.pair.com:/tmp/cvs-serv54621
Modified Files:
README lm.php uplng.sh
Removed Files:
mblm.php
Log Message:
Merged lm.php and mblm.php into one script; added XHTML support
Index: README
===================================================================
RCS file: /cvsroot/geeklog/tools/lm/README,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** README 21 Mar 2008 20:26:05 -0000 1.2
--- README 27 Apr 2008 09:48:06 -0000 1.3
***************
*** 1,5 ****
! lm.php v0.7
! These little scripts merge a Geeklog (foreign) language file with the
english.php language file, so that new strings added to english.php are
automatically added to the other language file as well.
--- 1,5 ----
! lm.php v0.8
! This little script merges a Geeklog (foreign) language file with the
english.php language file, so that new strings added to english.php are
automatically added to the other language file as well.
***************
*** 7,36 ****
Usage:
! lm.php langfile.php > new-langfile.php
! mblm.php does the same but for UTF-8 language files. It requires a PHP version
! with multi-byte string support built in (--enable-mbstring option). Otherwise,
! it works exactly like lm.php.
! These scripts, while written in PHP, are supposed to be run from the command
! line and thus require the CLI version of PHP to be installed on your
! computer. They also display the merged language file on the screen, so you
! should redirect the output to a new file. They also expects to find the
english.php language file in the current directory.
! What they can do:
- add new individual strings and string arrays to the language file
- do some pretty printing
! What they can not do:
- - remove obsoleted strings
- detect changed strings
- Since we don't usually remove obsoleted strings from Geeklog (in the hope
- that they can be reused at a later date), the first issue shouldn't be a
- problem.
-
For changes in existing strings, it is recommended that you subscribe to
the geeklog-translations mailing list, where such information will be posted
--- 7,32 ----
Usage:
! php lm.php langfile.php > new-langfile.php
! If the filename of the language file contains 'utf-8', lm.php assumes it to
! be in UTF-8 encoding. It then requires a PHP version with multi-byte string
! support built in (--enable-mbstring option).
! This script, while written in PHP, is supposed to be run from the command
! line and thus requires the CLI version of PHP to be installed on your
! computer. It also displays the merged language file on the screen, so you
! should redirect the output to a new file. It also expects to find the
english.php language file in the current directory.
! What it can do:
- add new individual strings and string arrays to the language file
- do some pretty printing
+ - remove obsoleted strings
! What it can not do:
- detect changed strings
For changes in existing strings, it is recommended that you subscribe to
the geeklog-translations mailing list, where such information will be posted
***************
*** 53,54 ****
--- 49,52 ----
0.6 updated for Geeklog 1.4.1
0.7 updated for Geeklog 1.5.0
+ 0.8 merged lm.php and mblm.php into one script; added XHTML support
+
Index: lm.php
===================================================================
RCS file: /cvsroot/geeklog/tools/lm/lm.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** lm.php 21 Mar 2008 20:26:05 -0000 1.2
--- lm.php 27 Apr 2008 09:48:06 -0000 1.3
***************
*** 33,37 ****
// $Id$
! $VERSION = '0.7';
// Prevent PHP from reporting uninitialized variables
--- 33,37 ----
// $Id$
! $VERSION = '0.8';
// Prevent PHP from reporting uninitialized variables
***************
*** 47,50 ****
--- 47,66 ----
}
+ $mb = false;
+ if (strpos($filename, '_utf-8') !== false) {
+ $mb = true;
+
+ if (!function_exists('mb_strpos')) {
+ echo "Sorry, this script needs a PHP version that has multibyte support compiled in.\n\n";
+ exit;
+ } else if (!function_exists('mb_ereg_replace')) {
+ echo "Sorry, this script needs a PHP version with the mb_ereg_replace function compiled in.\n\n";
+ exit;
+ }
+
+ mb_regex_encoding('UTF-8');
+ mb_internal_encoding('UTF-8');
+ }
+
// list of all variables accessed in the language file
***************
*** 68,72 ****
// load the English language file
! require_once ('english.php');
// save the english text strings
--- 84,88 ----
// load the English language file
! require_once 'english.php';
// save the english text strings
***************
*** 160,163 ****
--- 176,227 ----
/**
+ * My mb-save replacement for some(!) string replacements
+ *
+ */
+ function my_str_replace($s1, $s2, $s3)
+ {
+ global $mb;
+
+ if ($mb) {
+ return mb_ereg_replace($s1, $s2, $s3);
+ } else {
+ return str_replace($s1, $s2, $s3);
+ }
+ }
+
+ /**
+ * My mb-save replacement for some(!) use cases of strpos
+ *
+ */
+ function my_strpos($s1, $s2)
+ {
+ global $mb;
+
+ if ($mb) {
+ return mb_strpos($s1, $s2);
+ } else {
+ return strpos($s1, $s2);
+ }
+ }
+
+ /**
+ * Replace <br> with '<br . XHTML . >' construct for XHTML compliance
+ *
+ */
+ function patch_br($txt)
+ {
+ global $mb;
+
+ if ($mb) {
+ $fc = mb_substr($txt, 0, 1);
+ } else {
+ $fc = substr($txt, 0, 1);
+ }
+
+ return my_str_replace('<br>',
+ '<br' . $fc . ' . XHTML . ' . $fc . '>', $txt);
+ }
+
+ /**
* Merge two language arrays
*
***************
*** 168,171 ****
--- 232,237 ----
function mergeArrays($ENG, $OTHER, $arrayName, $comment = '')
{
+ global $mb;
+
$numElements = sizeof($ENG);
$counter = 0;
***************
*** 184,188 ****
foreach ($ENG as $key => $txt) {
$counter++;
! if (is_numeric ($key)) {
echo " $key => ";
} else {
--- 250,254 ----
foreach ($ENG as $key => $txt) {
$counter++;
! if (is_numeric($key)) {
echo " $key => ";
} else {
***************
*** 190,207 ****
}
$newtxt = '';
! if (empty ($OTHER[$key])) {
// string does not exist in other language - use English text
$newtxt = $txt;
} else {
! // string exists in other language - keep it
! $newtxt = $OTHER[$key];
}
! $newtxt = str_replace ("\n", '\n', $newtxt);
if (is_array($newtxt)) { // mainly for the config selects
$quotedtext = 'array(';
foreach ($newtxt as $nkey => $ntxt) {
! $quotedtext .= "'" . str_replace("'", "\'", $nkey) . "' => ";
if ($ntxt === true) {
$quotedtext .= 'true';
--- 256,280 ----
}
$newtxt = '';
! if (empty($OTHER[$key])) {
// string does not exist in other language - use English text
$newtxt = $txt;
} else {
! if (isset($ENG[$key]) && empty($ENG[$key])) {
! // string is now empty in English language file - remove it
! $newtxt = '';
! } else {
! // string exists in other language - keep it
! $newtxt = $OTHER[$key];
! }
}
! if (!is_array($newtxt)) {
! $newtxt = my_str_replace("\n", '\n', $newtxt);
! }
if (is_array($newtxt)) { // mainly for the config selects
$quotedtext = 'array(';
foreach ($newtxt as $nkey => $ntxt) {
! $quotedtext .= "'" . my_str_replace("'", "\'", $nkey) . "' => ";
if ($ntxt === true) {
$quotedtext .= 'true';
***************
*** 211,219 ****
$quotedtext .= $ntxt;
} else {
! $quotedtext .= "'" . str_replace("'", "\'", $ntxt) . "'";
}
$quotedtext .= ', ';
}
! $quotedtext = substr($quotedtext, 0, -2);
$quotedtext .= ')';
--- 284,296 ----
$quotedtext .= $ntxt;
} else {
! $quotedtext .= "'" . my_str_replace("'", "\'", $ntxt) . "'";
}
$quotedtext .= ', ';
}
! if ($mb) {
! $quotedtext = mb_substr($quotedtext, 0, -2);
! } else {
! $quotedtext = substr($quotedtext, 0, -2);
! }
$quotedtext .= ')';
***************
*** 222,245 ****
$quotedtext = "array('True' => TRUE, 'False' => FALSE)";
}
! } else if (strpos ($newtxt, '{$') === false) {
! if (strpos ($newtxt, '\n') === false) {
// text contains neither variables nor line feeds,
// so enclose it in single quotes
! $newtxt = str_replace ("'", "\'", $newtxt);
$quotedtext = "'" . $newtxt . "'";
} else {
// text contains line feeds - enclose in double quotes so
// they can be interpreted
! $newtxt = str_replace ('"', '\"', $newtxt);
$quotedtext = '"' . $newtxt . '"';
}
} else {
// text contains variables
! $newtxt = str_replace ('$', '\$', $newtxt);
! $newtxt = str_replace ('{\$', '{$', $newtxt);
! $newtxt = str_replace ('"', '\"', $newtxt);
$quotedtext = '"' . $newtxt . '"';
}
if ($counter != $numElements) {
$quotedtext .= ',';
--- 299,333 ----
$quotedtext = "array('True' => TRUE, 'False' => FALSE)";
}
!
! // ??? $quotedtext = mb_ereg_replace("\n", '\n', $quotedtext);
! } else if (my_strpos ($newtxt, '{$') === false) {
! if (my_strpos ($newtxt, '\n') === false) {
// text contains neither variables nor line feeds,
// so enclose it in single quotes
! $newtxt = my_str_replace("'", "\'", $newtxt);
$quotedtext = "'" . $newtxt . "'";
} else {
// text contains line feeds - enclose in double quotes so
// they can be interpreted
! $newtxt = my_str_replace('"', '\"', $newtxt);
$quotedtext = '"' . $newtxt . '"';
}
} else {
// text contains variables
! if ($mb) {
! $newtxt = mb_ereg_replace('\$', '\$', $newtxt);
! // backslash attack!
! $newtxt = mb_ereg_replace('\{\\\\\$', '{$', $newtxt);
! $newtxt = mb_ereg_replace('"', '\"', $newtxt);
! } else {
! $newtxt = str_replace('$', '\$', $newtxt);
! $newtxt = str_replace('{\$', '{$', $newtxt);
! $newtxt = str_replace('"', '\"', $newtxt);
! }
$quotedtext = '"' . $newtxt . '"';
}
+ $quotedtext = patch_br($quotedtext);
+
if ($counter != $numElements) {
$quotedtext .= ',';
***************
*** 362,366 ****
mergeArrays($ENGAD, $LANG_ADMIN, 'LANG_ADMIN', "Admin - Strings\n\nThese are some standard strings used by core functions as well as plugins to\ndisplay administration lists and edit pages");
! mergeArrays($ENG_commentcodes, $LANG_commentcodes, 'LANG_commentcodes', "Localisation of the texts for the various drop-down menus that are actually\nstored in the database. If these exist, they override the texts from the\ndatabase.");
mergeArrays($ENG_commentmodes, $LANG_commentmodes, 'LANG_commentmodes', false);
mergeArrays($ENG_cookiecodes, $LANG_cookiecodes, 'LANG_cookiecodes', false);
--- 450,456 ----
mergeArrays($ENGAD, $LANG_ADMIN, 'LANG_ADMIN', "Admin - Strings\n\nThese are some standard strings used by core functions as well as plugins to\ndisplay administration lists and edit pages");
! echo "# Localisation of the texts for the various drop-down menus that are actually\n# stored in the database. If these exist, they override the texts from the\n# database.\n";
!
! mergeArrays($ENG_commentcodes, $LANG_commentcodes, 'LANG_commentcodes', false);
mergeArrays($ENG_commentmodes, $LANG_commentmodes, 'LANG_commentmodes', false);
mergeArrays($ENG_cookiecodes, $LANG_cookiecodes, 'LANG_cookiecodes', false);
***************
*** 373,378 ****
echo "\n";
! mergeArrays($ENG_CONFIG, $LANG_CONFIG, 'LANG_CONFIG', 'Localization of the Admin Configuration UI');
mergeArrays($ENG_configsections['Core'], $LANG_configsections['Core'], "LANG_configsections['Core']", false);
mergeArrays($ENG_confignames['Core'], $LANG_confignames['Core'], "LANG_confignames['Core']", false);
--- 463,470 ----
echo "\n";
+ separator();
+ echo "# Localization of the Admin Configuration UI\n";
! mergeArrays($ENG_CONFIG, $LANG_CONFIG, 'LANG_CONFIG', false);
mergeArrays($ENG_configsections['Core'], $LANG_configsections['Core'], "LANG_configsections['Core']", false);
mergeArrays($ENG_confignames['Core'], $LANG_confignames['Core'], "LANG_confignames['Core']", false);
Index: uplng.sh
===================================================================
RCS file: /cvsroot/geeklog/tools/lm/uplng.sh,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** uplng.sh 21 Mar 2008 20:26:05 -0000 1.2
--- uplng.sh 27 Apr 2008 09:48:06 -0000 1.3
***************
*** 48,52 ****
# paths to the lm.php and mblm.php scripts
lm=$basedir/cvs.geeklog.net/tools/lm/lm.php
- mblm=$basedir/cvs.geeklog.net/tools/lm/mblm.php
--- 48,51 ----
***************
*** 63,74 ****
cd $destpath
for l in $files; do
! utf=`grep -i 'LANG_CHARSET.*utf-8' $langpath/$l`
! if [ -z "$utf" ]; then
! echo "$l"
! php $lm $langpath/$l > $l
! else
! echo "$l (utf-8)"
! php $mblm $langpath/$l > $l
! fi
done
--- 62,67 ----
cd $destpath
for l in $files; do
! echo "$l"
! php $lm $langpath/$l > $l
done
--- mblm.php DELETED ---
More information about the geeklog-cvs
mailing list