Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve installation language fallback system #34241

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 8 additions & 16 deletions install-dev/classes/controllerHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,17 @@ public function __construct()
$detect_language = $this->language->detectLanguage();

if (empty($this->session->lang)) {
$this->session->lang = $detect_language['primarytag'];
// Set the en as default fallback in case we can't detect a better one
$this->session->lang = 'en';
if (isset($detect_language['primarytag'])
&& in_array($detect_language['primarytag'], $this->language->getIsoList())) {
$this->session->lang = $detect_language['primarytag'];
}
}

Context::getContext()->language = $this->language->getLanguage(
$this->session->lang ?: false
);

Context::getContext()->language = $this->language->getLanguage($this->session->lang);
$this->translator = Context::getContext()->getTranslator(true);

if (isset($this->session->lang)) {
$lang = $this->session->lang;
} else {
$lang = (isset($detect_language['primarytag'])) ? $detect_language['primarytag'] : false;
}

if (!in_array($lang, $this->language->getIsoList())) {
$lang = 'en';
}
$this->language->setLanguage($lang);
$this->language->setLanguage($this->session->lang);

if (empty(self::getSteps())) {
$this->initSteps();
Expand Down
2 changes: 1 addition & 1 deletion src/PrestaShopBundle/Install/LanguageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function getCountriesByLanguage(?string $iso = null): array
public function detectLanguage()
{
// This code is from a php.net comment : http://www.php.net/manual/fr/reserved.variables.server.php#94237
$split_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$split_languages = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) : [];
if (!is_array($split_languages)) {
return false;
}
Expand Down