Changedlang file convention to avoid need for server restart after *.po file change.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 17 Jul 2010 16:19:36 +0000 (16:19 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 17 Jul 2010 16:19:36 +0000 (16:19 +0000)
includes/lang/gettext.php
includes/lang/language.php

index ec2a3b8bd3ace6782edc2e4cbac5c68073b2e07f..f2115a9aa95a17b46932072b77faab517d6554e8 100644 (file)
@@ -119,16 +119,17 @@ class gettext_native_support
     /**
      * Add a translation domain.
      */
-    function add_domain($domain, $path=false)
+    function add_domain($domain, $path=false, $version='')
     {
         if ($path === false) 
-        {
-            bindtextdomain($domain, "./locale/");
-        } 
-        else 
-        { 
-            bindtextdomain($domain, $path);
-        }
+               $path = "./locale";
+               if ($version) {
+       // To avoid need for apache server restart after change of *.mo file
+       // we have to include file version as part of filename.
+       // This is alternative naming convention: $domain = $version.'/'.$domain;
+                       $domain .= '-'.$version;
+               }
+        bindtextdomain($domain, $path);
         //bind_textdomain_codeset($domain, $encoding);
         textdomain($domain);
     }
@@ -286,8 +287,12 @@ class gettext_php_support extends gettext_native_support
      * @param string $path optional -- Repository path
      * @throws GetText_Error
      */
-    function add_domain($domain, $path = "./locale/")
+    function add_domain($domain, $path = "./locale/", $version ='')
     {   
+       if ($version) {
+                       $domain .= '-'.$version;
+               }
+
         if (array_key_exists($domain, $this->_domains)) 
         { 
             return; 
index 0b8ba215021c68587c14f33a58c96e33e90db989..54302ebe5a1fe887ff1359a3ae51a633d865fbfb 100644 (file)
@@ -22,6 +22,7 @@ class language
        var $encoding;          // eg. UTF-8, CP1256, ISO8859-1
        var     $dir;                   // Currently support for Left-to-Right (ltr) and
                                                // Right-To-Left (rtl)
+       var $version; // lang package version
        var $is_locale_file;
        
        function language($name, $code, $encoding, $dir = 'ltr') 
@@ -60,13 +61,14 @@ class language
                        $this->name = $lang['name'];
                        $this->code = $lang['code'];
                        $this->encoding = $lang['encoding'];
+                       $this->version = $lang['version'];
                        $this->dir = isset($lang['rtl']) ? 'rtl' : 'ltr';
                        $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc";
                        $this->is_locale_file = file_exists($locale);
                }
 
                $_SESSION['get_text']->set_language($this->code, $this->encoding);
-               $_SESSION['get_text']->add_domain($this->code, $path_to_root . "/lang");
+               $_SESSION['get_text']->add_domain($this->code, $path_to_root . "/lang", $this->version);
 
                // Necessary for ajax calls. Due to bug in php 4.3.10 for this 
                // version set globally in php.ini