Sfoglia il codice sorgente

fixes from u1 (default login + i18n)

Serghey Rodin 9 anni fa
parent
commit
4b8a2c3f38
2 ha cambiato i file con 89 aggiunte e 66 eliminazioni
  1. 76 65
      web/inc/i18n.php
  2. 13 1
      web/login/index.php

+ 76 - 65
web/inc/i18n.php

@@ -44,69 +44,80 @@ function __() {
     $args = func_get_args();
     array_unshift($args,$_SESSION['language']);
     return call_user_func_array("_translate",$args);
-}
-
-/**
- * Detects user language from Accept-Language HTTP header.
- * @param string Fallback language (default: 'en')
- * @return string Language code (such as 'en' and 'ja')
- */
-function detect_user_language($fallback='en') {
-    static $user_lang = '';
-
-    // Already detected
-    if (!empty($user_lang)) return $user_lang;
-
-    // Check if Accept-Language header is available
-    if (!isset($_SERVER) ||
-        !isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ||
-        !is_string($_SERVER['HTTP_ACCEPT_LANGUAGE'])
-    ) {
-        // Store result for reusing
-        $user_lang = $fallback;
-        return $user_lang;
-    }
-
-    // Sort Accept-Language by `q` value
-    $accept_langs = explode(',', preg_replace('/\s/', '', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])));
-    $accept_langs_sorted = array() ;
-    foreach ($accept_langs as $lang) {
-        $div = explode(';q=', $lang, 2);
-        if (count($div) < 2) {
-            // `q` value was not specfied
-            // -> Set default `q` value (1)
-            $div[] = '1';
-        }
-        list($code, $q) = $div;
-        if (preg_match('/^[\w\-]+$/', $code)) {
-            // Acceptable language code
-            $accept_langs_sorted[$code] = (double)$q;
-        }
-    }
-    arsort($accept_langs_sorted);
-
-    // List languages
-    exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
-    $languages = json_decode(implode('', $output), true);
-    unset($output);
-
-    // Find best matching language
-    foreach ($accept_langs_sorted as $user_lang => $dummy) {
-        $decision = '';
-        foreach ($languages as $prov_lang) {
-            if (strlen($decision) > strlen($prov_lang)) continue;
-            if (strpos($user_lang, $prov_lang) !== false) {
-                $decision = $prov_lang;
-            }
-        }
-        if (!empty($decision)) {
-            // Store result for reusing
-            $user_lang = $decision;
-            return $user_lang;
-        }
-    }
-
-    // Store result for reusing
-    $user_lang = $fallback;
-    return $user_lang;
+}
+
+/**
+ * Detects user language from Accept-Language HTTP header.
+ * @param string Fallback language (default: 'en')
+ * @return string Language code (such as 'en' and 'ja')
+ */
+function detect_user_language($fallback='en') {
+    static $user_lang = '';
+
+    // Already detected
+    if (!empty($user_lang)) return $user_lang;
+
+    // Check if Accept-Language header is available
+    if (!isset($_SERVER) ||
+        !isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ||
+        !is_string($_SERVER['HTTP_ACCEPT_LANGUAGE'])
+    ) {
+        // Store result for reusing
+        $user_lang = $fallback;
+        return $user_lang;
+    }
+
+
+    // Sort Accept-Language by `q` value
+    $accept_langs = explode(',', preg_replace('/\s/', '', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])));
+    $accept_langs_sorted = array() ;
+    foreach ($accept_langs as $lang) {
+        $div = explode(';q=', $lang, 2);
+        if (count($div) < 2) {
+            // `q` value was not specfied
+            // -> Set default `q` value (1)
+            $div[] = '1';
+        }
+        list($code, $q) = $div;
+        if (preg_match('/^[\w\-]+$/', $code)) {
+            // Acceptable language code
+            $accept_langs_sorted[$code] = (double)$q;
+        }
+    }
+    arsort($accept_langs_sorted);
+
+    // List languages
+    exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
+    $languages = json_decode(implode('', $output), true);
+    unset($output);
+
+    // Find best matching language
+    foreach ($accept_langs_sorted as $user_lang => $dummy) {
+        $decision = '';
+        foreach ($languages as $prov_lang) {
+            if (strlen($decision) > strlen($prov_lang)) continue;
+            if (strpos($user_lang, $prov_lang) !== false) {
+                $decision = $prov_lang;
+            }
+        }
+        if (!empty($decision)) {
+            // Store result for reusing
+            $user_lang = $decision;
+            return $user_lang;
+        }
+    }
+
+    // Store result for reusing
+    $user_lang = $fallback;
+    return $user_lang;
+}
+
+/**
+ * Detects user language .
+ * @param string Fallback language (default: 'en')
+ * @return string Language code (such as 'en' and 'ja')
+ */
+
+function detect_login_language(){
+
 }

+ 13 - 1
web/login/index.php

@@ -94,7 +94,19 @@ foreach ($sys_arr as $key => $value) {
 }
 
 // Detect language
-if (empty($_SESSION['language'])) $_SESSION['language'] = detect_user_language();
+if (empty($_SESSION['language'])) {
+    $output = '';
+    exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
+    $config = json_decode(implode('', $output), true);
+    $lang = $config['config']['LANGUAGE'];
+
+    $output = '';
+    exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
+    $languages = json_decode(implode('', $output), true);
+    if(in_array($lang, $languages)){
+        $_SESSION['language'] = $lang;
+    }
+}
 
 require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$_SESSION['language'].'.php');
 require_once('../templates/header.html');