diff --git a/common.php b/common.php index 61888bb..6c5ac28 100644 --- a/common.php +++ b/common.php @@ -42,7 +42,7 @@ header("Cross-Origin-Resource-Policy: same-origin"); const LANGUAGES = [ 'de' => ['name' => 'Deutsch', 'locale' => 'de_DE', 'flag' => '🇩🇪', 'show_in_menu' => true], 'en' => ['name' => 'English', 'locale' => 'en_GB', 'flag' => '🇬🇧', 'show_in_menu' => true], - 'ru' => ['name' => 'Русский', 'locale' => 'ru_RU', 'flag' => '🇷🇺', 'show_in_menu' => false], + 'ru' => ['name' => 'Русский', 'locale' => 'ru_RU', 'flag' => '🇷🇺', 'show_in_menu' => true], ]; $language = 'en'; $locale = 'en_GB'; @@ -54,6 +54,25 @@ if(isset($_REQUEST['lang']) && isset(LANGUAGES[$_REQUEST['lang']])){ }elseif(isset($_COOKIE['language']) && isset(LANGUAGES[$_COOKIE['language']])){ $locale = LANGUAGES[$_COOKIE['language']]['locale']; $language = $_COOKIE['language']; +}elseif(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ + $prefLocales = array_reduce( + explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']), + function (array $res, string $el) { + list($l, $q) = array_merge(explode(';q=', $el), [1]); + $res[$l] = (float) $q; + return $res; + }, []); + arsort($prefLocales); + foreach($prefLocales as $l => $q){ + $lang = locale_lookup(array_keys(LANGUAGES), $l); + if(!empty($lang)){ + $locale = LANGUAGES[$lang]['locale']; + $language = $lang; + setcookie('language', $lang, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ($_SERVER['HTTPS'] ?? '' === 'on'), 'httponly' => true, 'samesite' => 'Strict']); + break; + } + } + } putenv('LC_ALL='.$locale); setlocale(LC_ALL, $locale); diff --git a/locale/ru_RU/LC_MESSAGES/main-website.mo b/locale/ru_RU/LC_MESSAGES/main-website.mo index 9ec32b0..3fb3609 100644 Binary files a/locale/ru_RU/LC_MESSAGES/main-website.mo and b/locale/ru_RU/LC_MESSAGES/main-website.mo differ diff --git a/locale/ru_RU/LC_MESSAGES/main-website.po b/locale/ru_RU/LC_MESSAGES/main-website.po index 0e47a87..f34958b 100644 --- a/locale/ru_RU/LC_MESSAGES/main-website.po +++ b/locale/ru_RU/LC_MESSAGES/main-website.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-12-18 16:02+0100\n" -"PO-Revision-Date: 2022-12-23 11:13+0100\n" +"PO-Revision-Date: 2022-12-23 13:26+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: ru_RU\n" @@ -21,7 +21,7 @@ msgstr "" #: index.php:6 msgid "Daniel - Home" -msgstr "" +msgstr "Daniel - Домашняя страница" #: index.php:10 msgid "" @@ -31,7 +31,7 @@ msgstr "" #: index.php:14 common.php:81 msgid "Home" -msgstr "" +msgstr "Домашняя страница" #: index.php:15 msgid "" @@ -319,15 +319,15 @@ msgstr "" #: contact.php:6 msgid "Daniel - Contact" -msgstr "" +msgstr "Daniel - Контакт" #: contact.php:10 msgid "Contact Daniel Winzen" -msgstr "" +msgstr "Контакт Daniel Winzen" #: contact.php:14 common.php:91 msgid "Contact" -msgstr "" +msgstr "Контакт" #: contact.php:15 msgid "" @@ -658,7 +658,7 @@ msgstr "Вы можете написать мне." #: common.php:82 msgid "Chat" -msgstr "" +msgstr "Чат" #: common.php:83 msgid "Online-Test" @@ -1647,7 +1647,7 @@ msgstr "" #: chat/index.php:15 msgid "After 9 years, I'm shutting down the chat for good." -msgstr "Спустя девять лет, я вынужден закрыть свой чат навсегда" +msgstr "Спустя девять лет, я вынужден закрыть свой чат навсегда." #: chat/index.php:16 msgid ""