refactor: streamline language file loading

Simplified the logic for loading language files by consolidating into a single loop. Now, the base English file and potential browser language files are loaded in sequence, ensuring a more efficient and clearer process. Removed redundant checks and code for language alias handling.
This commit is contained in:
Kumi 2024-08-30 09:18:56 +02:00
parent 38586826e2
commit 0f891ba6ea
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -58,29 +58,20 @@ $aliases = [
'zh-mo' => 'zh-hant', 'zh-mo' => 'zh-hant',
]; ];
if (isset($aliases[$lang])) {
$lang = $aliases[$lang];
}
// Load the language files // Load the language files
// Take English as a base // Take English as a base, then overwrite with the browser language
// E.g.: First load en.php, then de.php, then de-at.php
require_once 'lang/en.php';
// Get the browser language code (e.g. 'de' for 'de-DE')
// Load that language file if available
$language_code = explode('-', $lang)[0]; $language_code = explode('-', $lang)[0];
$language_files = ["en", $language_code, $lang];
if (file_exists('lang/' . $language_code . '.php')) { foreach ($language_files as $language_file) {
require_once 'lang/' . $language_code . '.php'; if (file_exists('lang/' . $language_file . '.php')) {
} require_once 'lang/' . $language_file . '.php';
// If a region-specific language file is available, load that one
if ($language_code != $lang) {
if (isset($aliases[$language_code])) {
$lang = $aliases[$language_code];
}
if (file_exists('lang/' . $lang . '.php')) {
require_once 'lang/' . $lang . '.php';
} }
} }