]> git.agnieray.net Git - galette.git/commitdiff
Try to find default lang for all supported locales
authorJohan Cwiklinski <johan@x-tnd.be>
Mon, 29 Nov 2021 01:57:56 +0000 (02:57 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 29 Nov 2021 01:57:56 +0000 (02:57 +0100)
galette/lib/Galette/Core/I18n.php
galette/lib/Galette/Core/Login.php

index dd7cbb912f89bcd72f7e805561a5f6c1fe47254c..9c16001a1a12c6056349769ab597c389f70d4651 100644 (file)
@@ -88,13 +88,20 @@ class I18n
             //try to determine user language
             $dlang = self::DEFAULT_LANG;
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
-                $blang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
-                if (substr($blang, 0, 2) == 'fr') {
-                    $dlang = 'fr_FR';
-                } elseif (substr($blang, 0, 2) == 'en') {
-                    $dlang = 'en_US';
-                } else {
-                    $dlang = self::DEFAULT_LANG;
+                $preferred_locales = array_reduce(
+                    explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']),
+                    function ($res, $el) {
+                        list($l, $q) = array_merge(explode(';q=', $el), [1]);
+                        $res[$l] = (float) $q;
+                        return $res;
+                    }, []);
+                arsort($preferred_locales);
+
+                foreach (array_keys($preferred_locales) as $preferred_locale) {
+                    if (array_key_exists(str_replace('-', '_', $preferred_locale), $this->langs)) {
+                        $dlang = str_replace('-', '_', $preferred_locale);
+                        break;
+                    }
                 }
             }
             $this->changeLanguage($dlang);
@@ -193,7 +200,7 @@ class I18n
         $list = $this->getList();
         $al = array();
         foreach ($list as $l) {
-            //FIXME: shoudl use mb with sthing like:
+            //FIXME: should use mb with something like:
             //$strlen = mb_strlen($string, $encoding);
             //$firstChar = mb_substr($string, 0, 1, $encoding);
             //$then = mb_substr($string, 1, $strlen - 1, $encoding);
index 028cfb30c0db9bff5128c5a7813df1c905bcc168..d8d754fc2ea57a2e074649bea0e411f88caa0398 100644 (file)
@@ -230,9 +230,9 @@ class Login extends Authentication
         if ($row->priorite_statut < Members::NON_STAFF_MEMBERS) {
             $this->staff = true;
         }
-        //check if member is up to date
+        //check if member is up-to-date
         if ($row->bool_exempt_adh == true) {
-            //member is due free, he's up to date.
+            //member is due free, he's up-to-date.
             $this->uptodate = true;
         } else {
             //let's check from end date, if present