Fix bug when all requested locales are unavailable + automatically list locales
This commit is contained in:
parent
68cbec8a8d
commit
acc7409bfe
@ -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";
|
||||
|
||||
|
@ -11,6 +11,7 @@ $loc = array(
|
||||
'label_mainColor' => "label_mainColor",
|
||||
|
||||
'placeholder' => "placeholder",
|
||||
'placeholder_pixels' => "placeholder_pixels",
|
||||
|
||||
'value_default' => "value_default",
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user