我的作法是先查詢瀏覽器預設語言
如果沒有值再結合GEOIP去查詢所在地點,作為當地語言參考
真的都沒有的話,只好預設英語
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
$lang = $matches[1];
}
$hl = 'en-us';
//echo is_dir('./language/'.strtolower($lang));
if(empty($lang) || !is_dir('./language/'.strtolower($lang)))
{
$ip = $this->input->ip_address();
include("libraries/geoip.inc");
$gi = geoip_open("libraries/GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $ip);
if($country_code)
{
$country_code = strtolower($country_code);
$hl = $this->_switchcountry($country_code);
}
else{
$hl = 'en-us';
}
}
elseif(!empty($lang) && is_dir('./language/'.strtolower($lang))){
$hl = strtolower($lang);
}
else {
$hl = 'en-us';
}
認真過每一天
Matt,一個系統廠的全端程式設計工程師,開始認真過每一天,紀錄並分享,程式生活及旅遊人生
- Dec 13 Tue 2011 17:14
(codeigniter) 多語系製作,預設為'en-us'
全站熱搜
留言列表
發表留言