mirror of
https://github.com/ShaYmez/FreeSTAR-Status-Engine.git
synced 2024-11-23 20:58:46 -05:00
Remember locale in session
This commit is contained in:
parent
333d6b40b8
commit
57fdd4c442
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
function render_footer($admin = false)
|
||||
{
|
||||
global $best_match, $lang_names;
|
||||
global $lang_names;
|
||||
?>
|
||||
</div>
|
||||
<div id="footerwrap">
|
||||
@ -10,7 +10,7 @@ function render_footer($admin = false)
|
||||
<div class="col-md-4 text-left">Copyright © <?php echo date("Y");?> Vojtěch Sajdl</div>
|
||||
<div class="col-md-4 text-center">
|
||||
<div class="btn-group dropup">
|
||||
<button type="button" class="btn btn-primary"><?php echo '<img src="'.WEB_URL.'/locale/'.$best_match.'/flag.png" alt="'.$lang_names[$best_match].'">'.$lang_names[$best_match];?></button>
|
||||
<button type="button" class="btn btn-primary"><?php echo '<img src="'.WEB_URL.'/locale/'.$_SESSION['locale'].'/flag.png" alt="'.$lang_names[$_SESSION['locale']].'">'.$lang_names[$_SESSION['locale']];?></button>
|
||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="caret"></span>
|
||||
<span class="sr-only"><?php echo _("Toggle Dropdown");?></span>
|
||||
|
39
locale.php
39
locale.php
@ -5,8 +5,9 @@ function mb_ucfirst($string)
|
||||
return mb_strtoupper(mb_substr($string, 0, 1)).mb_strtolower(mb_substr($string, 1));
|
||||
}
|
||||
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
if (!isset($_SESSION['locale'])||isset($_GET['lang']))
|
||||
{
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
|
||||
|
||||
if (count($lang_parse[1])) {
|
||||
@ -23,18 +24,20 @@ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
|
||||
arsort($langs, SORT_NUMERIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$langs = array_flip($langs);
|
||||
$accepted_langs = glob(__DIR__ . '/locale/*' , GLOB_ONLYDIR);
|
||||
$lang_names = array();
|
||||
foreach ($accepted_langs as $key => $value) {
|
||||
|
||||
|
||||
$langs = array_flip($langs);
|
||||
$accepted_langs = glob(__DIR__ . '/locale/*' , GLOB_ONLYDIR);
|
||||
$lang_names = array();
|
||||
foreach ($accepted_langs as $key => $value) {
|
||||
$accepted_langs[$key] = basename($value);
|
||||
}
|
||||
}
|
||||
|
||||
$best_match = false;
|
||||
$best_match = false;
|
||||
|
||||
foreach ($langs as $lang) {
|
||||
foreach ($langs as $lang) {
|
||||
if (strlen($lang)>2){
|
||||
if (in_array($lang, $accepted_langs)){
|
||||
$best_match = $lang;
|
||||
@ -51,18 +54,22 @@ foreach ($langs as $lang) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($accepted_langs as $lang) {
|
||||
foreach ($accepted_langs as $lang) {
|
||||
$lang_names[$lang] = mb_ucfirst(locale_get_display_language($lang, $lang));
|
||||
}
|
||||
}
|
||||
|
||||
if ($best_match === false){
|
||||
if ($best_match === false){
|
||||
$best_match = DEFAULT_LANGUAGE;
|
||||
}
|
||||
|
||||
$_SESSION['locale'] = $best_match;
|
||||
}
|
||||
|
||||
setlocale(LC_ALL, $best_match.".UTF-8");
|
||||
|
||||
setlocale(LC_ALL, $_SESSION['locale'].".UTF-8");
|
||||
|
||||
bindtextdomain("server-status", __DIR__ . "/locale/");
|
||||
bind_textdomain_codeset($best_match, "utf-8");
|
||||
bind_textdomain_codeset($_SESSION['locale'], "utf-8");
|
||||
textdomain("server-status");
|
Loading…
Reference in New Issue
Block a user