Fix bug when all requested locales are unavailable + automatically list locales

This commit is contained in:
Miraty 2022-05-30 20:51:16 +02:00
parent 68cbec8a8d
commit acc7409bfe
2 changed files with 4 additions and 3 deletions

View File

@ -13,19 +13,19 @@ require "vendor/autoload.php";
define("LIBREQR_VERSION", "2.0.0dev");
// Defines the locale to be used
$locale = DEFAULT_LOCALE;
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales);
$clientLocales = explode(',', $clientLocales);
$availableLocales = array('en', 'fr', 'oc', 'template');
foreach (array_diff(scandir("locales"), array('..', '.')) as $key => $localeFile)
$availableLocales[$key] = basename($localeFile, ".php");
foreach ($clientLocales as $clientLocale) {
if (in_array($clientLocale, $availableLocales)) {
$locale = $clientLocale;
break;
}
}
} else {
$locale = DEFAULT_LOCALE;
}
require "locales/" . $locale . ".php";

View File

@ -11,6 +11,7 @@ $loc = array(
'label_mainColor' => "label_mainColor",
'placeholder' => "placeholder",
'placeholder_pixels' => "placeholder_pixels",
'value_default' => "value_default",