Ejemplo n.º 1
0
 protected static function get_lang_cache_key()
 {
     # 当前语言key
     $libs_key = array();
     foreach (Core::$include_path as $libs) {
         foreach ($libs as $path) {
             $libs_key[] = $path;
         }
     }
     $libs_key = md5(implode(',', $libs_key));
     $key = 'lang_cache_by_' . $libs_key . '_for_' . implode('_', I18n::accept_language());
     return $key;
 }
Ejemplo n.º 2
0
 /**
  * 获取$accept_language
  *
  * @return array
  */
 protected static function accept_language()
 {
     if (null !== I18n::$accept_language) {
         return I18n::$accept_language;
     }
     # 客户端语言包
     $accept_language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
     $lang_config = Core::config('lang');
     # 匹配语言设置
     # zh-CN,zh;q=0.8,zh-TW;q=0.6
     if ($accept_language && preg_match_all('#([a-z]+\\-[a-z]+),|([a-z]+\\-[a-z]+);#i', $accept_language, $matches)) {
         $accept_language = $matches[0];
         $accept_language = array_values(array_slice($accept_language, 0, 2));
         //只取前2个语言设置
         $accept_language[0] = strtolower(rtrim($accept_language[0], ';,'));
         if (isset($accept_language[1])) {
             $accept_language[1] = strtolower(rtrim($accept_language[1], ';,'));
         }
         if ($lang_config && !in_array($lang_config, $accept_language)) {
             $accept_language[] = $lang_config;
         }
     } else {
         if ($lang_config) {
             $accept_language = array($lang_config);
         } else {
             $accept_language = array('zh-cn');
         }
     }
     I18n::$accept_language = $accept_language;
     return $accept_language;
 }