https://developers.google.com/search/do ... onal-sites
Read googles recommendations for multi language / multi country sites and pick the one that is most suitable
Default OC does not set language based on the url and there is no language indication for SEO urls nor non-SEO urls.
Search engine indexing will always get the default language regardless of the seo url language.
The language switcher does switch the language but does not switch to the seo url.
You can use a language indication in the url, many times discussed how to do that on this forum, search for it and read the google documentation above to enable an informed decision.
You could use this which simply adds the redirects in the correct language for all enabled languages to the view and uses that when selected.
(these are total file replacements so backup first if you have made changes there!)
Total replacement for catalog/controller/common/language.php
Code: Select all
<?php
class ControllerCommonLanguage extends Controller {
public function index() {
$this->load->language('common/language');
$data['action'] = $this->url->link('common/language/language', '', $this->request->server['HTTPS']);
$data['code'] = $this->session->data['language'];
$this->load->model('localisation/language');
$data['languages'] = array();
$results = $this->model_localisation_language->getLanguages();
// save current language id
$language_id_save = $this->config->get('config_language_id');
// for each enabled language set the name, code and seo url in that language
foreach ($results as $result) {
if ($result['status']) {
$url = '';
// determine redirect url for language
$this->config->set('config_language_id',$result['language_id']);
$this->session->data['language'] = $result['code'];
if (!isset($this->request->get['route'])) {
$url_data = $this->request->get;
unset($url_data['_route_']);
if ($url_data) $url = '&' . urldecode(http_build_query($url_data, '', '&'));
$redirect = $this->url->link('common/home', $url, $this->request->server['HTTPS']);
} else {
$url_data = $this->request->get;
unset($url_data['_route_']);
$route = $url_data['route'];
unset($url_data['route']);
if ($url_data) $url = '&' . urldecode(http_build_query($url_data, '', '&'));
$redirect = $this->url->link($route, $url, $this->request->server['HTTPS']);
}
// add the language redirect data to the view interface
$data['languages'][] = array(
'name' => $result['name'],
'code' => $result['code'],
'href' => $redirect
);
}
}
// restore current language id
$this->session->data['language'] = $data['code'];
$this->config->set('config_language_id',$language_id_save);
return $this->load->view('common/language', $data);
}
public function language() {
$this->load->model('localisation/language');
$languages = $this->model_localisation_language->getLanguages();
$url = '';
// do we have a valid code from the language selection
if (isset($this->request->post['code']) && array_key_exists($this->request->post['code'],$languages) && $languages[$this->request->post['code']]['status']) {
// set the requested language
$this->session->data['language'] = $this->request->post['code'];
// use the correct redirect
$this->response->redirect($this->request->post['redirect_'.$this->request->post['code']]);
} else {
// otherwise just go home
$this->response->redirect($this->url->link('common/home', $url, $this->request->server['HTTPS']));
}
}
}
Total replacement for catalog/view/theme/default/template/common/language.twig
Code: Select all
{% if languages|length > 1 %}
<div class="pull-left">
<form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-language">
<div class="btn-group">
<button class="btn btn-link dropdown-toggle" data-toggle="dropdown">
{% for language in languages %}
{% if language.code == code %}
<img src="catalog/language/{{ language.code }}/{{ language.code }}.png" alt="{{ language.name }}" title="{{ language.name }}"> <span class="hidden-xs hidden-sm hidden-md">{{ language.name }}</span>
{% endif %}
{% endfor %}
<span class="hidden-xs"> <i class="fa fa-caret-down"></i></span></button>
<ul class="dropdown-menu">
{% for language in languages %}
{% if language.code != code %}
<li><button class="btn btn-link btn-block language-select" type="button" name="{{ language.code }}"><img src="catalog/language/{{ language.code }}/{{ language.code }}.png" alt="{{ language.name }}" title="{{ language.name }}" /> {{ language.name }}</button></li>
<input type="hidden" name="redirect_{{ language.code }}" value="{{ language.href }}" />
{% endif %}
{% endfor %}
</ul>
</div>
<input type="hidden" name="code" value="" />
</form>
</div>
{% endif %}