[geeklog-cvs] tools/lm README, 1.3, 1.4 lm.php, 1.3, 1.4 uplng.sh, 1.3, 1.4

Dirk Haun dhaun at qs1489.pair.com
Sun Apr 27 13:11:15 EDT 2008


Update of /cvsroot/geeklog/tools/lm
In directory qs1489.pair.com:/tmp/cvs-serv72462

Modified Files:
	README lm.php uplng.sh 
Log Message:
Moved updating code into includes, allowing to support plugins


Index: README
===================================================================
RCS file: /cvsroot/geeklog/tools/lm/README,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** README	27 Apr 2008 09:48:06 -0000	1.3
--- README	27 Apr 2008 17:11:13 -0000	1.4
***************
*** 1,3 ****
! lm.php v0.8
  
  This little script merges a Geeklog (foreign) language file with the
--- 1,3 ----
! lm.php v0.9
  
  This little script merges a Geeklog (foreign) language file with the
***************
*** 7,11 ****
  Usage:
  
!     php lm.php langfile.php > new-langfile.php
  
  If the filename of the language file contains 'utf-8', lm.php assumes it to
--- 7,14 ----
  Usage:
  
!     php lm.php langfile.php [module] > new-langfile.php
! 
! Where "module" is the name of the plugin to update (or empty for a Core
! language file).
  
  If the filename of the language file contains 'utf-8', lm.php assumes it to
***************
*** 24,27 ****
--- 27,31 ----
  - do some pretty printing
  - remove obsoleted strings
+ - update plugin language files
  
  What it can not do:

Index: lm.php
===================================================================
RCS file: /cvsroot/geeklog/tools/lm/lm.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** lm.php	27 Apr 2008 09:48:06 -0000	1.3
--- lm.php	27 Apr 2008 17:11:13 -0000	1.4
***************
*** 33,37 ****
  // $Id$
  
! $VERSION = '0.8';
  
  // Prevent PHP from reporting uninitialized variables
--- 33,37 ----
  // $Id$
  
! $VERSION = '0.9';
  
  // Prevent PHP from reporting uninitialized variables
***************
*** 43,50 ****
      echo "lm.php v{$VERSION}\n";
      echo "This is free software; see the source for copying conditions.\n\n";
!     echo "Usage: {$GLOBALS['argv'][0]} langfile.php > new-langfile.php\n\n";
      exit;
  }
  
  $mb = false;
  if (strpos($filename, '_utf-8') !== false) {
--- 43,55 ----
      echo "lm.php v{$VERSION}\n";
      echo "This is free software; see the source for copying conditions.\n\n";
!     echo "Usage: {$GLOBALS['argv'][0]} langfile.php [module] > new-langfile.php\n\n";
      exit;
  }
  
+ $module = '';
+ if (!empty($GLOBALS['argv'][2])) {
+     $module = $GLOBALS['argv'][2];
+ }
+ 
  $mb = false;
  if (strpos($filename, '_utf-8') !== false) {
***************
*** 84,172 ****
  
  // load the English language file
! require_once 'english.php';
! 
! // save the english text strings
! $ENG01 = $LANG01;
! // $LANG02 moved to the Calendar plugin as of Geeklog 1.4.1
! $ENG03 = $LANG03;
! $ENG04 = $LANG04;
! $ENGMY = $LANG_MYACCOUNT;
! $ENG05 = $LANG05;
! // $LANG06 moved to the Links plugin as of Geeklog 1.4.0
! // $LANG07 moved to the Polls plugin as of Geeklog 1.4.0
! $ENG08 = $LANG08;
! $ENG09 = $LANG09;
! $ENG10 = $LANG10;
! $ENG11 = $LANG11;
! $ENG12 = $LANG12;
! // there are no $LANG13-$LANG19
! $ENG20 = $LANG20;
! $ENG21 = $LANG21;
! // $LANG22 moved to the Calendar plugin as of Geeklog 1.4.1
! // $LANG23 moved to the Links plugin as of Geeklog 1.4.0
! $ENG24 = $LANG24;
! // $LANG25 moved to the Polls plugin as of Geeklog 1.4.0
! // there is no $LANG26
! $ENG27 = $LANG27;
! $ENG28 = $LANG28;
! $ENG29 = $LANG29;
! // $LANG30 moved to the Calendar plugin as of Geeklog 1.4.1
! $ENG31 = $LANG31;
! $ENG32 = $LANG32;
! $ENG33 = $LANG33;
! 
! $ENGMS = $MESSAGE;
! $ENGAC = $LANG_ACCESS;
! $ENGDB = $LANG_DB_BACKUP;
! $ENGBT = $LANG_BUTTONS;
! $ENG404 = $LANG_404;
! $ENGLO = $LANG_LOGIN;
! $ENGPD = $LANG_PDF;
! $ENGTB = $LANG_TRB;
! $ENGDI = $LANG_DIR;
! $ENGWN = $LANG_WHATSNEW;
! $ENGMO = $LANG_MONTH;
! $ENGWK = $LANG_WEEK;
! $ENGAD = $LANG_ADMIN;
! 
! $ENG_commentcodes = $LANG_commentcodes;
! $ENG_commentmodes = $LANG_commentmodes;
! $ENG_cookiecodes = $LANG_cookiecodes;
! $ENG_dateformats = $LANG_dateformats;
! $ENG_featurecodes = $LANG_featurecodes;
! $ENG_frontpagecodes = $LANG_frontpagecodes;
! $ENG_postmodes = $LANG_postmodes;
! $ENG_sortcodes = $LANG_sortcodes;
! $ENG_trackbackcodes = $LANG_trackbackcodes;
! 
! $ENG_CONFIG = $LANG_CONFIG;
! $ENG_configsections['Core'] = $LANG_configsections['Core'];
! $ENG_confignames['Core'] = $LANG_confignames['Core'];
! $ENG_configsubgroups['Core'] = $LANG_configsubgroups['Core'];
! $ENG_configsubgroups['Core'] = $LANG_configsubgroups['Core'];
! $ENG_fs['Core'] = $LANG_fs['Core'];
! $ENG_configselects['Core'] = $LANG_configselects['Core'];
! 
! unset($LANG_MONTH);
! unset($LANG_WEEK);
! 
! // now load the language file we want to update
! require_once $langfile;
! 
! // try to rescue translated day and months names
! 
! if (!isset ($LANG_WEEK[1]) && isset ($LANG30[1])) {
!     $LANG_WEEK = array ();
!     for ($i = 1; $i <= 7; $i++) {
!         $LANG_WEEK[$i] = $LANG30[$i];
!     }
  }
  
! if (!isset ($LANG_MONTH[1]) && isset ($LANG30[13])) {
!     $LANG_MONTH = array ();
!     for ($i = 1; $i <= 12; $i++) {
!         $LANG_MONTH[$i] = $LANG30[$i + 12];
!     }
  }
  
  function separator()
--- 89,105 ----
  
  // load the English language file
! if (empty($module)) {
!     require_once 'language/english.php';
! } else {
!     require_once 'plugins/' . $module . '/language/english.php';
  }
  
! $lastp = strrpos($_SERVER['PHP_SELF'], DIRECTORY_SEPARATOR);
! if ($lastp === false) {
!     $incpath = '.' . DIRECTORY_SEPARATOR;
! } else {
!     $incpath = substr($_SERVER['PHP_SELF'], 0, $lastp + 1);
  }
+ $incpath .= 'include' . DIRECTORY_SEPARATOR;
  
  function separator()
***************
*** 223,226 ****
--- 156,193 ----
  }
  
+ function prepareText($newtxt)
+ {
+     global $mb;
+ 
+     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 . '"';
+     }
+ 
+     return $quotedtext;
+ }
+ 
  /**
  * Merge two language arrays
***************
*** 301,329 ****
  
              // ??? $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 . '"';
          }
  
--- 268,273 ----
  
              // ??? $quotedtext = mb_ereg_replace("\n", '\n', $quotedtext);
          } else {
!             $quotedtext = prepareText($newtxt);
          }
  
***************
*** 343,346 ****
--- 287,306 ----
  }
  
+ function mergeString($eng, $other, $name)
+ {
+     global $mb;
+ 
+     if (empty($other)) {
+         $newtxt = $eng;
+     } else {
+         $newtxt = $other;
+     }
+ 
+     $quotedtext = prepareText($newtxt);
+     $quotedtext = patch_br($quotedtext);
+ 
+     echo "\$$name = $quotedtext;\n";
+ }
+ 
  /**
  * Read the credits / copyright from the other language file.
***************
*** 381,385 ****
  // MAIN
  
! $credits = readCredits ($langfile);
  
  // output starts here ...
--- 341,345 ----
  // MAIN
  
! $credits = readCredits($langfile);
  
  // output starts here ...
***************
*** 391,475 ****
  }
  
! echo "\n\$LANG_CHARSET = '$LANG_CHARSET';\n";
! if (isset ($LANG_DIRECTION)) {
!     echo "\$LANG_DIRECTION = '$LANG_DIRECTION';\n\n";
  } else {
!     echo "\n";
  }
- 
- separator();
- echo "# Array Format:\n";
- echo "# \$LANGXX[YY]:  \$LANG - variable name\n";
- echo "#               XX    - file id number\n";
- echo "#               YY    - phrase id number\n";
- separator();
- echo "\n";
- separator();
- echo "# USER PHRASES - These are file phrases used in end user scripts\n";
- separator();
- echo "\n";
- 
- mergeArrays($ENG01, $LANG01, 'LANG01', 'lib-common.php');
- mergeArrays($ENG03, $LANG03, 'LANG03', 'comment.php');
- mergeArrays($ENG04, $LANG04, 'LANG04', 'users.php');
- mergeArrays($ENGMY,  $LANG_MYACCOUNT, 'LANG_MYACCOUNT', "Customize if need to modify the Tabbed navbar MyAccount panels used.\nArray index key matches preference div id");
- mergeArrays($ENG05, $LANG05, 'LANG05', 'index.php');
- mergeArrays($ENG08, $LANG08, 'LANG08', 'profiles.php');
- mergeArrays($ENG09, $LANG09, 'LANG09', 'search.php');
- mergeArrays($ENG10, $LANG10, 'LANG10', 'stats.php');
- mergeArrays($ENG11, $LANG11, 'LANG11', 'article.php');
- mergeArrays($ENG12, $LANG12, 'LANG12', 'submit.php');
- 
- separator();
- echo "# ADMIN PHRASES - These are file phrases used in admin scripts\n";
- separator();
- echo "\n";
- 
- mergeArrays($ENG20, $LANG20, 'LANG20', 'admin/auth.inc.php');
- mergeArrays($ENG21, $LANG21, 'LANG21', 'admin/block.php');
- mergeArrays($ENG24, $LANG24, 'LANG24', 'admin/story.php');
- mergeArrays($ENG27, $LANG27, 'LANG27', 'admin/topic.php');
- mergeArrays($ENG28, $LANG28, 'LANG28', 'admin/user.php');
- mergeArrays($ENG29, $LANG29, 'LANG29', 'admin/moderation.php');
- mergeArrays($ENG31, $LANG31, 'LANG31', 'admin/mail.php');
- mergeArrays($ENG32, $LANG32, 'LANG32', 'admin/plugins.php');
- mergeArrays($ENG33, $LANG33, 'LANG33', 'admin/syndication.php');
- 
- mergeArrays($ENGMS,  $MESSAGE, 'MESSAGE', 'confirmation and error messages');
- mergeArrays($ENGAC,  $LANG_ACCESS, 'LANG_ACCESS');
- mergeArrays($ENGDB,  $LANG_DB_BACKUP, 'LANG_DB_BACKUP', 'admin/database.php');
- mergeArrays($ENGBT,  $LANG_BUTTONS, 'LANG_BUTTONS');
- mergeArrays($ENG404, $LANG_404, 'LANG_404', '404.php');
- mergeArrays($ENGLO,  $LANG_LOGIN, 'LANG_LOGIN', 'login form');
- mergeArrays($ENGPD,  $LANG_PDF, 'LANG_PDF', 'pdfgenerator.php');
- mergeArrays($ENGTB,  $LANG_TRB, 'LANG_TRB', 'trackback.php');
- mergeArrays($ENGDI,  $LANG_DIR, 'LANG_DIR', 'directory.php');
- mergeArrays($ENGWN,  $LANG_WHATSNEW, 'LANG_WHATSNEW', "\"What's New\" Time Strings\n\nFor the first two strings, you can use the following placeholders.\nOrder them so it makes sense in your language:\n%i    item, \"Stories\"\n%n    amount, \"2\", \"20\" etc.\n%t    time, \"2\" (weeks)\n%s    scale, \"hrs\", \"weeks\"");
- mergeArrays($ENGMO,  $LANG_MONTH, 'LANG_MONTH', 'Month names');
- mergeArrays($ENGWK,  $LANG_WEEK, 'LANG_WEEK', 'Weekdays');
- 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);
- mergeArrays($ENG_dateformats, $LANG_dateformats, 'LANG_dateformats', false);
- mergeArrays($ENG_featurecodes, $LANG_featurecodes, 'LANG_featurecodes', false);
- mergeArrays($ENG_frontpagecodes, $LANG_frontpagecodes, 'LANG_frontpagecodes', false);
- mergeArrays($ENG_postmodes, $LANG_postmodes, 'LANG_postmodes', false);
- mergeArrays($ENG_sortcodes, $LANG_sortcodes, 'LANG_sortcodes', false);
- mergeArrays($ENG_trackbackcodes, $LANG_trackbackcodes, 'LANG_trackbackcodes', false);
- 
- 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);
- mergeArrays($ENG_configsubgroups['Core'], $LANG_configsubgroups['Core'], "LANG_configsubgroups['Core']", false);
- mergeArrays($ENG_fs['Core'], $LANG_fs['Core'], "LANG_fs['Core']", false);
- mergeArrays($ENG_configselects['Core'], $LANG_configselects['Core'], "LANG_configselects['Core']", false);
  
  echo "\n?>";
--- 351,361 ----
  }
  
! // load the module file which does the rest
! 
! if (empty($module)) {
!     require_once $incpath . 'core.inc';
  } else {
!     require_once $incpath . $module . '.inc';
  }
  
  echo "\n?>";

Index: uplng.sh
===================================================================
RCS file: /cvsroot/geeklog/tools/lm/uplng.sh,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** uplng.sh	27 Apr 2008 09:48:06 -0000	1.3
--- uplng.sh	27 Apr 2008 17:11:13 -0000	1.4
***************
*** 32,50 ****
  
  # Installation and usage:
! # - copy this script into the "language" directory of a local Geeklog install
! #   Note that all *.php files in that directory will be removed!
  # - adjust paths below
! # - cd into the language directory, run the script
  
  # just a basedir to save some typing ...
  basedir=/Users/dirk/darwin
  
! # location of the language directory in your local copy of the CVS repository
! langpath=$basedir/cvs.geeklog.net/Geeklog-1.x/language
  
! # target language directory - where this script is located
! destpath=$basedir/work/language
  
! # paths to the lm.php and mblm.php scripts
  lm=$basedir/cvs.geeklog.net/tools/lm/lm.php
  
--- 32,51 ----
  
  # Installation and usage:
! # - copy this script into the /path/to/geeklog of a local Geeklog install
! #   Note that all *.php files in all of the language directories will be
! #   deleted and new language files will be created there
  # - adjust paths below
! # - cd /path/to/geeklog, run the script
  
  # just a basedir to save some typing ...
  basedir=/Users/dirk/darwin
  
! # the /path/to/geeklog of your local copy of the CVS repository
! cvspath=$basedir/cvs.geeklog.net/Geeklog-1.x
  
! # target directory - where this script is located aka /path/to/geeklog
! destpath=$basedir/work
  
! # path to the lm.php script and the include directory
  lm=$basedir/cvs.geeklog.net/tools/lm/lm.php
  
***************
*** 52,67 ****
  # you shouldn't need to change anything below ...
  
! cd $destpath
! rm -f *.php
  
! cd $langpath
! files=`ls -1 *.php | grep -v english.php`
  
! cp english.php $destpath
  
! cd $destpath
! for l in $files; do
!   echo "$l"
!   php $lm $langpath/$l > $l
! done
  
--- 53,88 ----
  # you shouldn't need to change anything below ...
  
! function doConvert() { # parameters: "to" "from" "module"
  
!   if [ -z "$3" ]; then
!     echo "=== Core ==="
  
!     modpath=$1/language
!     langpath=$2/language
!   else
!     echo "=== $3 ==="
  
!     modpath=$1/plugins/$3/language
!     langpath=$2/plugins/$3/language
!   fi
! 
!   cd $modpath
!   rm -f *.php
! 
!   cd $langpath
!   files=`ls -1 *.php | grep -v english.php | grep -v english_utf-8.php`
! 
!   cp english.php $modpath
!   cp english_utf-8.php $modpath
! 
!   cd $destpath
!   for l in $files; do
!     echo "$l"
!     php $lm $langpath/$l "$3" > $modpath/$l
!   done
! 
! }
! 
! doConvert $destpath $cvspath
! doConvert $destpath $cvspath "calendar"
  




More information about the geeklog-cvs mailing list