Thinkphp 多语言功能完善
博学站
人气:1.59W
thinkPHP是PHP国内最火的.框架没有之一,但是 原生代码对多语言识别有点不方便,今天本站小编为大家整理的Thinkphp 多语言功能完善,仅供学习参考,欢迎大家阅读浏览! thinkphp 原生代码对多语言识别有点不方便。下面代码增加的对语种的识别。 /** * 自动侦测设置获取语言选择 * @return string */ public static function detect() { // 自动侦测设置获取语言选择 $langSet = ''; if (isset($_GET[self::$langDetectVar])) { // url中设置了语言变量 $langSet = strtolower($_GET[self::$langDetectVar]); } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // 自动侦测浏览器语言 preg_match('/^([a-zd-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches); $langSet = strtolower($matches[1]); $acceptLangs = Config::get('header_accept_lang'); if (isset($acceptLangs[$langSet])) { $langSet = $acceptLangs[$langSet]; } elseif (isset(self::$acceptLanguage[$langSet])) { $langSet = self::$acceptLanguage[$langSet]; } } if(!empty($langSet)){ if(empty(self::$allowLangList) || in_array($langSet, self::$allowLangList)){ self::$range = $langSet; }else{ $tmp = explode('-',$langSet); if(count($tmp)>2) $langSet = $tmp[0].'-'.$tmp[count($tmp)-1]; if(in_array($langSet, self::$allowLangList)) self::$range = $langSet;//只包含语种+地区 else{ //只包含语种 $langSet = $tmp[0]; if(in_array($langSet, self::$allowLangList)) self::$range = $langSet; } } } return self::$range; }
猜你喜欢
- 1英语作文:HelpMyFatherGiveUpSmoking
- 2Thinkpad笔记本开机显示Tointerrruptnormalstartup解决方法
- 3linux下用phpize给PHP动态添加扩展
- 4Ought Parents to Give Children Pocket英语作文
- 5Why Public Speaking Is So Important 公共演说的重要性大学英语
- 6 Keeping Healthy Topic2 Section C教案教学反思
- 7Think Positive Thoughts Every Day英语作文
- 8分析thinkphp常见路径用法分析
- 9How Li Ming Keeps Healthy 高中英语作文
- 10php安装xdebug/pear/phpunit图文详解
- 11 PEP英语UnitThreeisthisyourskirt的教学设计
- 12英语作文The Happy Spring Festiva
- 13php配置文件phpini的方法参考
- 14高中英语作文Think Positive T
- 15Stephen Hawking初中英语作文
最近更新
- 1英语演讲稿《 I Am Tripping My Elephant Here》
- 2新概念英语青少版2a课文Unit 04:The top three persent
- 3《Right Diet To Keep Eyes Healthy》英语阅读训练
- 4三上英语M3Unit2《Point to the desk》教案
- 5城市功能完善建设领导发言
- 6Thinkphp搜索时首页分页和搜索页保持条件
- 7英语的美文:Keeping the Harvest
- 8The relationship between theory and practice大学英语作文
- 9The truth about money and happiness高中英语作文
- 10Having fun in the Water Park开心的水上乐园作文
- 11网月科技WiFi云计费功能完善
- 12In the park英语作文
- 132015年大学英语四级写作范文:Shopping through Media
- 14Compare with the domestic hen and the duck英语作文
- 15英语作文:keeping healthy
- 16php配置文件phpini的方法
- 17PHP配置文件详解php.ini
- 18系统功能语言学
- 19多功能室标语