From 3912c67965f7a6d17c973508880d6f805aa072e4 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:24:45 +0200 Subject: [PATCH] Skip applying translations if no locale data is loaded --- public/scripts/i18n.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/scripts/i18n.js b/public/scripts/i18n.js index 94bf85085..cf5e0bd9a 100644 --- a/public/scripts/i18n.js +++ b/public/scripts/i18n.js @@ -81,6 +81,10 @@ async function getMissingTranslations() { } export function applyLocale(root = document) { + if (!localeData || Object.keys(localeData).length === 0) { + return root; + } + const $root = root instanceof Document ? $(root) : $(new DOMParser().parseFromString(root, 'text/html')); //find all the elements with `data-i18n` attribute @@ -112,8 +116,8 @@ export function applyLocale(root = document) { function addLanguagesToDropdown() { for (const langObj of langs) { // Set the value to the language code const option = document.createElement('option'); - option.value = langObj["lang"]; // Set the value to the language code - option.innerText = langObj["display"]; // Set the display text to the language name + option.value = langObj['lang']; // Set the value to the language code + option.innerText = langObj['display']; // Set the display text to the language name $('#ui_language_select').append(option); }