diff --git a/locale.php b/locale.php index 5e5b372..a03a9a8 100644 --- a/locale.php +++ b/locale.php @@ -1,8 +1,54 @@ - $val) { + if ($val === '') $langs[$lang] = 1; + } + + arsort($langs, SORT_NUMERIC); + } +} + +$langs = array_flip($langs); + +$accepted_langs = glob(__DIR__ . '/locale/*' , GLOB_ONLYDIR); + +foreach ($accepted_langs as $key => $value) { + $accepted_langs[$key] = basename($value); +} + +$best_match = false; + +foreach ($langs as $lang) { + if (strlen($lang)>2){ + if (in_array($lang, $accepted_langs)){ + $best_match = $lang; + break; + } + }else{ + $possible = array_filter($accepted_langs, function($key) { + global $lang; + return strpos($key, $lang) === 0; + }); + + if (count($possible)){ + $best_match = $possible[0]; + break; + } + } +} + +if ($best_match === false){ + $best_match = DEFAULT_LANGUAGE; +} + +setlocale(LC_ALL, $best_match.".UTF-8"); bindtextdomain("server-status", __DIR__ . "/locale/"); -bind_textdomain_codeset(DEFAULT_LANGUAGE, "utf-8"); +bind_textdomain_codeset($best_match, "utf-8"); textdomain("server-status"); \ No newline at end of file