Change getLangFromHTTP()

For the header ACCEPT_LANGUAGE, which does not contain a separate code
for the main part of the language.
This commit is contained in:
Visman 2019-12-13 16:32:36 +07:00
parent 34fddd45e4
commit 2cdcd19568

View file

@ -259,15 +259,24 @@ class Current extends Action
{
if (! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs = $this->c->Func->getLangs();
$main = [];
foreach ($this->c->Func->langParse($_SERVER['HTTP_ACCEPT_LANGUAGE']) as $entry) {
$arr = \explode('-', $entry);
$arr = \explode('-', $entry, 2);
if (isset($arr[1])) {
$entry = $arr[0] . '_' . \strtoupper($arr[1]);
$main[] = $arr[0];
}
if (isset($langs[$entry])) {
return $langs[$entry];
}
}
if (! empty($main)) {
foreach ($main as $entry) {
if (isset($langs[$entry])) {
return $langs[$entry];
}
}
}
}
return $this->c->config->o_default_lang;
}