]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fixes autoLocale function by trying several way to find a correct one.
authorArthurHoaro <arthur@hoa.ro>
Thu, 12 Mar 2015 20:43:21 +0000 (21:43 +0100)
committernodiscc <nodiscc@gmail.com>
Tue, 31 Mar 2015 11:22:20 +0000 (13:22 +0200)
index.php

index 9ab70f6c32a8d2946308b3c1ff1bff80341f6859..7795a5974388e20b8a7f11b10ae5691950748fb7 100644 (file)
--- a/index.php
+++ b/index.php
@@ -302,12 +302,17 @@ function keepMultipleSpaces($text)
 // (Note that is may not work on your server if the corresponding local is not installed.)
 function autoLocale()
 {
-    $loc='en_US'; // Default if browser does not send HTTP_ACCEPT_LANGUAGE
+    $attempts = array('en_US'); // Default if browser does not send HTTP_ACCEPT_LANGUAGE
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"
     {   // (It's a bit crude, but it works very well. Preferred language is always presented first.)
-        if (preg_match('/([a-z]{2}(-[a-z]{2})?)/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) $loc=$matches[1];
+        if (preg_match('/([a-z]{2})-?([a-z]{2})?/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) {
+            $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
+            $attempts = array($loc, str_replace('_', '-', $loc),
+                $loc . '_' . strtoupper($loc), $loc . '_' . $loc,
+                $loc . '-' . strtoupper($loc), $loc . '-' . $loc);
+        }
     }
-    setlocale(LC_TIME,$loc);  // LC_TIME = Set local for date/time format only.
+    setlocale(LC_TIME, $attempts);  // LC_TIME = Set local for date/time format only.
 }
 
 // ------------------------------------------------------------------------------------------
@@ -549,7 +554,7 @@ function endsWith($haystack,$needle,$case=true)
 function linkdate2timestamp($linkdate)
 {
     $Y=$M=$D=$h=$m=$s=0;
-    $r = sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
+    sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
     return mktime($h,$m,$s,$M,$D,$Y);
 }