如何通过opencart中的url设置语言 [英] How to set language through url in opencart
问题描述
我想通过 url 更改语言,以便我的网站可以在搜索引擎中以不同语言显示.
例如:我希望用户通过这样的链接更改语言:
www.mysite.com/lang=ar
我使用的是 opencart 3.0.2
目前用户通过提交帖子请求的表单菜单进行更改,因此搜索引擎无法索引其他语言.
我该怎么做?
我成功地应用了这些步骤:
1- 打开目录/控制器/启动/startup.php
行后:
$languages = $this->model_localisation_language->getLanguages();
添加以下代码:
if(isset($this->request->get['lng'])){$this->session->data['language'] = $this->request->get['lng'];}
2- 将以下几行添加到 .htaccess 文件中:
RewriteRule ^en/([^?]*) index.php?_route_=$1&lng=en [L,QSA]RewriteRule ^ar/([^?]*) index.php?_route_=$1&lng=ar [L,QSA]
3- 向模板文件添加了语言标志:
{% 用于语言中的语言 %}<a href="/{{ language['code'] }}"><img src="catalog/language/{{ language['code'] }}/{{ language['code'] }}.png" alt="{{ language['name'] }}" title="{{ 语言['name'] }}"/></a>{% 结束为 %}
现在,当我导航到 www.mysite.com/en 时,它将转到英语,其他语言也是如此,现在搜索引擎可以索引其他语言的页面.
I'd like to change language through url so my site can appear in different languages in search engines.
e.g: I'd like the user to change language through a link like this:
www.mysite.com/lang=ar
I'm using opencart 3.0.2
Currently the user change through a form menu that submit post request, so search engine can't index the other languages.
How can I do that?
I successfully applied these steps:
1- open catalog/controller/startup/startup.php
after the line:
$languages = $this->model_localisation_language->getLanguages();
add the following code:
if(isset($this->request->get['lng'])){
$this->session->data['language'] = $this->request->get['lng'];
}
2- added the following lines to .htaccess file:
RewriteRule ^en/([^?]*) index.php?_route_=$1&lng=en [L,QSA]
RewriteRule ^ar/([^?]*) index.php?_route_=$1&lng=ar [L,QSA]
3- added languages flags to the template file:
<div class="languageFlags">
{% for language in languages %}
<a href="/{{ language['code'] }}">
<img src="catalog/language/{{ language['code'] }}/{{ language['code'] }}.png" alt="{{ language['name'] }}" title="{{ language['name'] }}" />
</a>
{% endfor %}
</div>
Now when I navigate to www.mysite.com/en it will go to English language and this is true for other languages, and now search engine can index other languages pages.
这篇关于如何通过opencart中的url设置语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!