提前致谢
我是 Magento 的新手,我需要帮助为用户切换语言。当客户访问我的网站时,它应该使用他们的 IP 来确定他们的国家并适本地切换语言。
例如,如果我从法国访问,我的网站应该以法语显示。如果任何其他国家/地区的其他人尝试,该网站应该使用该国家/地区的本地语言..
-杰特
最佳答案
我曾经为客户做过一次。这是我所做的。
先决条件:PHP 的 GeoIp 库。
1- 在您的 Magento 后台创建与语言相关的商店 View 。
2- 添加过滤系统:
2a - 编辑主/父主题的 page.xml 布局文件,并在第 35/36 行附近(在句柄中,添加:
<block type="page/html" name="country-filter" output="toHtml" template="page/html/country-filter.phtml" />
2b - 在您的主/父主题中创建一个模板/page/html/country-filter.phtml 并放置可以根据您的需要更改的代码:
if(!isset($_COOKIE['frontend'])) {
setcookie("frontend",session_id(),time()+60*60*24,"/","");
$ip = $_SERVER['REMOTE_ADDR'];
$country = geoip_country_name_by_name($ip);
switch($country) {
case 'France':
$url = $this->getUrl() . '?___store=YOUR_STORE_VIEW_CODE_FOR_FRANCE';
header( 'Location:' . $url) ;
/* (Maybe add "exit;" here)*/
break;
// (etc... for other cases)
default:
break; /* No need to specify a country/store view for default as you must have done that in System > Manage Stores in your Magento backend.*/
}
}
关于php - Magento 中的语言切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3354099/