Example #1
0
 public function detectLanguage()
 {
     $input = Input::getInstance('SERVER');
     //strstr()需要PHP5.3.0以上版本支持第三个参数,如果找不到,返回false
     $language = strstr($input->get('LANG', ''), '.', true);
     if (empty($language)) {
         $accept = $input->get('HTTP_ACCEPT_LANGUAGE', '');
         preg_match_all('/([a-z]{2}\\-?[A-Z]{0,2})/', $accept, $matches);
         foreach ($matches[0] as $language) {
             $language = str_replace('-', '_', $language);
             if (file_exists($this->locale_dir . '/' . $language)) {
                 break;
             }
         }
     }
     return $language;
 }
Example #2
0
 function detectLanguage()
 {
     $cB = Input::getInstance('SERVER');
     $JB = strstr($cB->get('LANG', ''), '.', true);
     if (empty($JB)) {
         $EF = $cB->get('HTTP_ACCEPT_LANGUAGE', '');
         preg_match_all('/([a-z]{2}\\-?[A-Z]{0,2})/', $EF, $MB);
         foreach ($MB[0] as $JB) {
             $JB = str_replace('-', '_', $JB);
             if (file_exists($this->locale_dir . '/' . $JB)) {
                 break;
             }
         }
     }
     return $JB;
 }