php - Magento 中的语言切换

标签 php magento

提前致谢

我是 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/

相关文章:

php - 使用 PHP 生成 XML 时的奇怪行为

configuration - Magento 配置 - 使用 frontend_model 时填充字段

forms - 我必须如何验证客户帐户注册表单中的复选框?

api - 使用 Magento API 获取产品

php - AWS EC2 实例每晚崩溃......仅运行 Magento

php - 通过 Composer 安装软件包后如何启动脚本?

PHP/MYSQL - 检索多个结果并创建数组

Magento topSearch 在模板中不起作用

php - 如何在 Zend Framework 2 中打开 PHP 错误报告?

PHP、MySQL : SELECT by individual timezone preferences