Skip to content

Commit

Permalink
Merge pull request #34241 from jolelievre/fix-install-language-fallback
Browse files Browse the repository at this point in the history
Improve installation language fallback system
  • Loading branch information
kpodemski committed Oct 12, 2023
2 parents 1c7e161 + cbf4063 commit 3e559f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
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

0 comments on commit 3e559f4

Please sign in to comment.