Parcourir la source

* Everything should be in the session now

Tyler Akins il y a 24 ans
Parent
commit
1874b0bd81
1 fichiers modifiés avec 26 ajouts et 3 suppressions
  1. 26 3
      functions/gettext.php

+ 26 - 3
functions/gettext.php

@@ -3,6 +3,8 @@
    /* Alternate to the system's built-in gettext.
     * relies on .po files (can't read .mo easily).
     * Uses the session for caching (speed increase)
+    * Possible use in other PHP scripts?  The only SM-specific thing is
+    *   $sm_language, I think
     */
      
    if (defined('gettext_php'))
@@ -16,16 +18,28 @@
       $gettext_php_loaded = false;
       session_register('gettext_php_loaded');
    }
-   
+   if (! isset($gettext_php_domain)) {
+      $gettext_php_domain = '';
+      session_register('gettext_php_translateStrings');
+   }
+   if (! isset($gettext_php_dir)) {
+      $gettext_php_dir = '';
+      session_register('gettext_php_translateStrings');
+   }
+   if (! isset($gettext_php_translateStrings)) {
+      $gettext_php_translateStrings = array();
+      session_register('gettext_php_translateStrings');
+   }
+
    function gettext_php_load_strings() {
       global $sm_language, $gettext_php_translateStrings,
          $gettext_php_domain, $gettext_php_dir, $gettext_php_loaded;
       
       // $sm_language gives 'en' for English, 'de' for German, etc.
-      // I didn't wanna use getenv or similar.
+      // I didn't wanna use getenv or similar, but you easily could change
+      // my code to do that.
       
       $gettext_php_translateStrings = array();
-      session_register('gettext_php_translateStrings');
       
       $filename = $gettext_php_dir;
       if (substr($filename, -1) != '/')
@@ -34,6 +48,7 @@
       
       $file = fopen($filename, 'r');
       if ($file === false)
+         // Uh-ho
          return;
 	  
       $key = '';
@@ -47,6 +62,9 @@
          if (ereg('^msgid "(.*)"$', $line, $match)) {
 	    if ($match[1] == '') {
 	       // Potential multi-line
+	       // msgid ""
+	       // "string string "
+	       // "string string"
 	       $key = '';
                $line = trim(fgets($file, 4096));
 	       while (ereg('^[ ]*"(.*)"[ ]*$', $line, $match)) {
@@ -54,11 +72,15 @@
 		  $line = trim(fgets($file, 4096));
 	       }
 	    } else {
+	       // msgid "string string"
 	       $key = $match[1];
 	    }
 	 } elseif (ereg('^msgstr "(.*)"$', $line, $match)) {
 	    if ($match[1] == '') {
 	       // Potential multi-line
+	       // msgstr ""
+	       // "string string "
+	       // "string string"
 	       $gettext_php_translateStrings[$key] = '';
 	       $line = trim(fgets($file, 4096));
 	       while (ereg('^[ ]*"(.*)"[ ]*$', $line, $match)) {
@@ -66,6 +88,7 @@
 		  $line = trim(fgets($file, 4096));
 	       }
 	    } else {
+	       // msgstr "string string"
 	       $gettext_php_translateStrings[$key] = $match[1];
 	    }
 	    $key = '';