mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Localization: Now the engine can detect browser's language and set it automatically
This commit is contained in:
parent
dddeeb9d72
commit
676c51dcda
1 changed files with 23 additions and 1 deletions
|
@ -106,6 +106,20 @@ function getLanguages(): array
|
||||||
return yaml_parse_file(OPENVK_ROOT . "/locales/list.yml")['list'];
|
return yaml_parse_file(OPENVK_ROOT . "/locales/list.yml")['list'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLanguageAvailable($lg): bool
|
||||||
|
{
|
||||||
|
$lg_temp = false;
|
||||||
|
foreach(getLanguages() as $lang) {
|
||||||
|
if ($lang['code'] == $lg) $lg_temp = true;
|
||||||
|
}
|
||||||
|
return $lg_temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBrowsersLanguage(): array
|
||||||
|
{
|
||||||
|
return mb_split(",", mb_split(";", $_SERVER['HTTP_ACCEPT_LANGUAGE'])[0]);
|
||||||
|
}
|
||||||
|
|
||||||
function eventdb(): ?DatabaseConnection
|
function eventdb(): ?DatabaseConnection
|
||||||
{
|
{
|
||||||
$conf = OPENVK_ROOT_CONF["openvk"]["credentials"]["eventDB"];
|
$conf = OPENVK_ROOT_CONF["openvk"]["credentials"]["eventDB"];
|
||||||
|
@ -181,6 +195,14 @@ return (function() {
|
||||||
|
|
||||||
setlocale(LC_TIME, "POSIX");
|
setlocale(LC_TIME, "POSIX");
|
||||||
|
|
||||||
|
// TODO: Default language in config
|
||||||
|
if(Session::i()->get("lang") == null) {
|
||||||
|
$languages = array_reverse(getBrowsersLanguage());
|
||||||
|
foreach($languages as $lg) {
|
||||||
|
if(isLanguageAvailable($lg)) setLanguage($lg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(empty($_SERVER["REQUEST_SCHEME"]))
|
if(empty($_SERVER["REQUEST_SCHEME"]))
|
||||||
$_SERVER["REQUEST_SCHEME"] = empty($_SERVER["HTTPS"]) ? "HTTP" : "HTTPS";
|
$_SERVER["REQUEST_SCHEME"] = empty($_SERVER["HTTPS"]) ? "HTTP" : "HTTPS";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue