How to set language through url in opencart
Asked Answered
B

1

7

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?

Bender answered 1/12, 2017 at 7:40 Comment(2)
Are you sure search engines dont index other languages?Plead
Yes, that's what happen with my site, because there are no url links to other languages, it's just a form list box with post method!Bender
B
5

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.

Bender answered 10/12, 2017 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.