Add an option to force used locale in config.inc.php

This commit is contained in:
Miraty 2020-10-12 18:48:53 +02:00
parent 3356db6555
commit 4eb11a1785
2 changed files with 26 additions and 17 deletions

View File

@ -13,10 +13,16 @@ deleteOldQR(60 * 60 * 24 * 7);
// FR : Nom du thème (doit être dans le dossier themes) // FR : Nom du thème (doit être dans le dossier themes)
$theme = "dark"; $theme = "dark";
// EN: Language used if those wanted by the user are not available // EN: Language used if those requested by the user are not available
// FR : Langue utilisée si celles demandées par l'utilisateurice ne sont pas disponibles // FR : Langue utilisée si celles demandées par l'utilisateurice ne sont pas disponibles
$locale = "fr"; // fr ou en $locale = "en"; // en || fr
$fileNameLenght = 32; // Longueur du nom du fichier du code QR // EN: Should the locales requested by the user be ignored?
// FR : Faut-il ignorer les langues demandées par l'utilisateurice ?
$forceLocale = false;
//$additionalText = "This LibreQR instance is hosted by <a href='https://foo.bar'>foo</a>."; // EN: Lenght of the QR code filename
// FR : Longueur du nom du fichier du code QR
$fileNameLenght = 32;
//$customText = "This LibreQR instance is hosted by <a href='https://foo.bar'>foo</a>.";

23
inc.php
View File

@ -2,30 +2,33 @@
require "config.inc.php"; require "config.inc.php";
// Defines locale used // Defines the locale used
$clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE']; if ($forceLocale == false) {
$clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales); $clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$clientLocales = explode(',', $clientLocales); $clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales);
$availableLocales = array('fr', 'en', 'template'); $clientLocales = explode(',', $clientLocales);
foreach ($clientLocales as $clientLocale) { $availableLocales = array('fr', 'en', 'template');
foreach ($clientLocales as $clientLocale) {
if (in_array($clientLocale, $availableLocales)) { if (in_array($clientLocale, $availableLocales)) {
$locale = $clientLocale; $locale = $clientLocale;
break; break;
} }
}
} }
require "locales/" . $locale . ".php"; require "locales/" . $locale . ".php";
// Defines root URL // Defines the root URL
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
$protocol = "https"; $protocol = "https";
else else
$protocol = "http"; $protocol = "http";
$instPath = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $rootPath = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$instPath = preg_replace('#\?.*$#', '', $instPath); $rootPath = preg_replace('#\?.*$#', '', $rootPath);
$instPath = preg_replace('#(manifest|opensearch|index).php$#i', '', $instPath); $rootPath = preg_replace('#(manifest|opensearch|index).php$#i', '', $rootPath);
require "themes/" . $theme . "/theme.php"; // Load theme require "themes/" . $theme . "/theme.php"; // Load theme
// Used to generate the filename of the QR code
function generateRandomString($length) { function generateRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters); $charactersLength = strlen($characters);