[*] LO : Fix PSCFV-10876: use IETF code to set language of shop, not 'iso' code, allows to distinguish between chinese variants etc.
This commit is contained in:
@@ -619,6 +619,35 @@ class LanguageCore extends ObjectModel
|
|||||||
return Db::getInstance()->getValue('SELECT `language_code` FROM `'._DB_PREFIX_.'lang` WHERE `iso_code` = \''.pSQL(strtolower($iso_code)).'\'');
|
return Db::getInstance()->getValue('SELECT `language_code` FROM `'._DB_PREFIX_.'lang` WHERE `iso_code` = \''.pSQL(strtolower($iso_code)).'\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getLanguageByIETFCode($code)
|
||||||
|
{
|
||||||
|
if (!Validate::isLanguageCode($code))
|
||||||
|
die(sprintf(Tools::displayError('Fatal error: IETF code %s is not correct'), $code));
|
||||||
|
|
||||||
|
// $code is in the form of 'xx-YY' where xx is the language code
|
||||||
|
// and 'YY' a country code identifying a variant of the language.
|
||||||
|
$lang_country = explode('-', $code);
|
||||||
|
// Get the language component of the code
|
||||||
|
$lang = $lang_country[0];
|
||||||
|
|
||||||
|
// Find the id_lang of the language.
|
||||||
|
// We look for anything with the correct language code
|
||||||
|
// and sort on equality with the exact IETF code wanted.
|
||||||
|
// That way using only one query we get either the exact wanted language
|
||||||
|
// or a close match.
|
||||||
|
$id_lang = Db::getInstance()->getValue(
|
||||||
|
'SELECT `id_lang` FROM '
|
||||||
|
.'`'._DB_PREFIX_.'lang` WHERE LEFT(`language_code`,2) = \''.pSQL($lang).'\' '
|
||||||
|
.'ORDER BY language_code = \''.pSQL($code).'\' DESC'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Instantiate the Language object if we found it.
|
||||||
|
if ($id_lang)
|
||||||
|
return new Language($id_lang);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return array (id_lang, iso_code)
|
* Return array (id_lang, iso_code)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -346,17 +346,12 @@ class ToolsCore
|
|||||||
/* Automatically detect language if not already defined, detect_language is set in Cookie::update */
|
/* Automatically detect language if not already defined, detect_language is set in Cookie::update */
|
||||||
if ((!$cookie->id_lang || isset($cookie->detect_language)) && 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)
|
$string = $array[0];
|
||||||
|
|
||||||
|
if (Validate::isLanguageCode($string))
|
||||||
{
|
{
|
||||||
$tab = explode('-', $array[0]);
|
$lang = Language::getLanguageByIETFCode($string);
|
||||||
$string = $tab[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$string = $array[0];
|
|
||||||
if (Validate::isLanguageIsoCode($string))
|
|
||||||
{
|
|
||||||
$lang = new Language(Language::getIdByIso($string));
|
|
||||||
if (Validate::isLoadedObject($lang) && $lang->active && $lang->isAssociatedToShop())
|
if (Validate::isLoadedObject($lang) && $lang->active && $lang->isAssociatedToShop())
|
||||||
{
|
{
|
||||||
Context::getContext()->language = $lang;
|
Context::getContext()->language = $lang;
|
||||||
@@ -364,7 +359,7 @@ class ToolsCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($cookie->detect_language))
|
if (isset($cookie->detect_language))
|
||||||
unset($cookie->detect_language);
|
unset($cookie->detect_language);
|
||||||
|
|
||||||
@@ -374,7 +369,7 @@ class ToolsCore
|
|||||||
|
|
||||||
$iso = Language::getIsoById((int)$cookie->id_lang);
|
$iso = Language::getIsoById((int)$cookie->id_lang);
|
||||||
@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');
|
@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');
|
||||||
|
|
||||||
return $iso;
|
return $iso;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user