]> dev.renevier.net Git - syp.git/blobdiff - inc/langutils.php
fixes notices
[syp.git] / inc / langutils.php
index 8a81b9c0f465a73f327e3c785259608011ec298e..758fef65f0141f5366821cb317047bced616a483 100644 (file)
@@ -11,7 +11,9 @@ function ptrans ($str) {
 function trans ($str) {
     global $translations, $lang;
 
-    $res = $translations[$lang][$str];
+    if (isset ($translations[$lang]) and isset($translations[$lang][$str])) {
+        $res = $translations[$lang][$str];
+    }
     if (!isset ($res) || strlen ($res) == 0) {
         return $str;
     } else {
@@ -27,16 +29,17 @@ function parse_accept_language () {
         $accepts = explode (',',
                         strtolower ($_SERVER ['HTTP_ACCEPT_LANGUAGE']));
         foreach ($accepts as $acc) {
-            if (preg_match ('/^\s*([a-zA-Z-]+)\s*$/', $acc, $matches)) {
+            if (preg_match ('/^\s*([a-zA-Z]+)(-[a-zA-Z]+)?\s*$/', $acc, $matches)) {
                 $possibilities [$matches [1]] = 1.0;
             }
-            if (preg_match ('/^\s*([a-zA-Z-]+)\s*;\s*q\s*=\s*([0-9\.]+)\s*$/',
+            if (preg_match ('/^\s*([a-zA-Z]+)(-[a-zA-Z]+)?\s*;\s*q\s*=\s*([0-9\.]+)\s*$/',
                             $acc, $matches)) {
-                $val = floatval ($matches [2]);
+                $val = floatval ($matches [3]);
                 if ($val > 1.0) {
                     $val = 1.0;
                 }
-                $possibilities [$matches [1]] = $val;
+                $ceil = (isset ($possibilities[$matches[1]]))? $possibilities[$matches[1]]: 0;
+                $possibilities [$matches [1]] = max ($val, $ceil);
             }
         }
         arsort ($possibilities);