Improved locales checking.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 23 Jan 2010 18:27:05 +0000 (18:27 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 23 Jan 2010 18:27:05 +0000 (18:27 +0000)
includes/lang/gettext.php
includes/lang/language.php

index cc2f04d02a8ec1ccea44affff70c5620b9639152..ec2a3b8bd3ace6782edc2e4cbac5c68073b2e07f 100644 (file)
@@ -43,7 +43,7 @@ function get_text_init($managerType = GETTEXT_NATIVE) {
 }
 
 function raise_error($str) {
-//     echo "$str";
+       error_log($str);
        return 1;
 }
 
@@ -73,7 +73,17 @@ class gettext_native_support
 
         //$set = setlocale(LC_ALL, "$lang_code");
         //$set = setlocale(LC_ALL, "$encoding");
-        $set = setlocale(LC_ALL, $lang_code.".".$encoding);
+
+               // cover a couple of country/encoding variants 
+               $up = strtoupper($encoding);
+               $low = strtolower($encoding);
+               $lshort = strtr($up, '-','');
+               $ushort = strtr($low, '-','');
+
+        $set = setlocale(LC_ALL, $lang_code.".".$encoding, 
+                       $lang_code.".".$up, $lang_code.".".$low,
+                       $lang_code.".".$ushort, $lang_code.".".$lshort);
+                       
         setlocale(LC_NUMERIC, 'C'); // important for numeric presentation etc.
         if ($set === false) 
         {
@@ -85,7 +95,27 @@ class gettext_native_support
         }
                //return 0;
     }
-    
+    /**
+        *      Check system support for given language nedded for gettext.
+        */
+       function check_support($lang_code, $encoding)
+    {
+               $old = setlocale(LC_MESSAGES, '0');
+               $up = strtoupper($encoding);
+               $low = strtolower($encoding);
+               $lshort = strtr($up, '-','');
+               $ushort = strtr($low, '-','');
+
+        $test = setlocale(LC_MESSAGES,
+                       $lang_code.".".$encoding, 
+                       $lang_code.".".$up,
+                       $lang_code.".".$low,
+                       $lang_code.".".$ushort,
+                       $lang_code.".".$lshort) !== false;
+
+               setlocale(LC_MESSAGES, $old);
+               return $test;
+       }
     /**
      * Add a translation domain.
      */
@@ -102,7 +132,7 @@ class gettext_native_support
         //bind_textdomain_codeset($domain, $encoding);
         textdomain($domain);
     }
-    
+
     /**
      * Retrieve translation for specified key.
      *
@@ -242,7 +272,13 @@ class gettext_php_support extends gettext_native_support
             }            
         }
     }
-    
+    /**
+        *      Check system support for given language (dummy).
+        */
+       function check_support($lang_code, $encoding)
+    {
+               return true;
+    }
     /**
      * Add a translation domain.
      *
index e983384fc2b82e6d0fd2d99c6b99150b4ea267c0..824a528ca7ee2da58d35a6aef0c6c13f656064a6 100644 (file)
@@ -26,8 +26,10 @@ class language
        
        function language($name, $code, $encoding, $dir = 'ltr') 
        {
+               global $dflt_lang;
+               
                $this->name = $name;
-               $this->code = $code ? $code : 'en_GB';
+               $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'en_GB');
                $this->encoding = $encoding;
                $this->dir = $dir;
        }