[-] FO : Force browser language detection in Tools::setCookieLanguage
This commit is contained in:
@@ -298,7 +298,11 @@ class CookieCore
|
|||||||
|
|
||||||
//checks if the language exists, if not choose the default language
|
//checks if the language exists, if not choose the default language
|
||||||
if (!$this->_standalone && !Language::getLanguage((int)$this->id_lang))
|
if (!$this->_standalone && !Language::getLanguage((int)$this->id_lang))
|
||||||
|
{
|
||||||
$this->id_lang = Configuration::get('PS_LANG_DEFAULT');
|
$this->id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||||||
|
// set detect_language to force going through Tools::setCookieLanguage to figure out browser lang
|
||||||
|
$this->detect_language = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -343,8 +343,8 @@ class ToolsCore
|
|||||||
$cookie->id_lang = null;
|
$cookie->id_lang = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Automatically detect language if not already defined */
|
/* Automatically detect language if not already defined, detect_language is set in Cookie::update */
|
||||||
if (!$cookie->id_lang && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
if ((!$cookie->id_lang || isset($cookie->detect_language)) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
||||||
{
|
{
|
||||||
$array = explode(',', Tools::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
|
$array = explode(',', Tools::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
|
||||||
if (Tools::strlen($array[0]) > 2)
|
if (Tools::strlen($array[0]) > 2)
|
||||||
@@ -358,9 +358,17 @@ class ToolsCore
|
|||||||
{
|
{
|
||||||
$lang = new Language(Language::getIdByIso($string));
|
$lang = new Language(Language::getIdByIso($string));
|
||||||
if (Validate::isLoadedObject($lang) && $lang->active)
|
if (Validate::isLoadedObject($lang) && $lang->active)
|
||||||
|
{
|
||||||
|
$language = new Language((int)$lang->id);
|
||||||
|
if (Validate::isLoadedObject($language))
|
||||||
|
Context::getContext()->language = $language;
|
||||||
$cookie->id_lang = (int)$lang->id;
|
$cookie->id_lang = (int)$lang->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($cookie->detect_language))
|
||||||
|
unset($cookie->detect_language);
|
||||||
|
|
||||||
/* If language file not present, you must use default language file */
|
/* If language file not present, you must use default language file */
|
||||||
if (!$cookie->id_lang || !Validate::isUnsignedId($cookie->id_lang))
|
if (!$cookie->id_lang || !Validate::isUnsignedId($cookie->id_lang))
|
||||||
|
|||||||
Reference in New Issue
Block a user