From 2e278e732317cca389aef8f5d258774d05f6e6bb Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 26 Apr 2024 22:57:42 +0300 Subject: [PATCH] Fix missing localization for unknown locale --- public/scripts/i18n.js | 23 ++++++++++++----------- public/scripts/secrets.js | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/public/scripts/i18n.js b/public/scripts/i18n.js index 649b17cdb..def67def4 100644 --- a/public/scripts/i18n.js +++ b/public/scripts/i18n.js @@ -1,5 +1,5 @@ import { registerDebugFunction } from './power-user.js'; -import { updateSecretDisplay } from './secrets.js' +import { updateSecretDisplay } from './secrets.js'; const storageKey = 'language'; const overrideLanguage = localStorage.getItem(storageKey); @@ -14,9 +14,9 @@ const localeData = await getLocaleData(localeFile); */ async function getLocaleData(language) { let supportedLang = findLang(language); - if (!supportedLang) { - return {}; - } + if (!supportedLang) { + return {}; + } const data = await fetch(`./locales/${language}.json`).then(response => { console.log(`Loading locale data from ./locales/${language}.json`); @@ -30,20 +30,21 @@ async function getLocaleData(language) { } function findLang(language) { - var supportedLang = langs.find(x => x.lang === language); + var supportedLang = langs.find(x => x.lang === language); if (!supportedLang) { console.warn(`Unsupported language: ${language}`); } - return supportedLang; + return supportedLang; } async function getMissingTranslations() { const missingData = []; - - // Determine locales to search for untranslated strings - const langsToProcess = localeFile == 'en' ? langs : [findLang(localeFile)]; - + + // Determine locales to search for untranslated strings + const isNotSupported = !findLang(localeFile); + const langsToProcess = (isNotSupported || localeFile == 'en') ? langs : [findLang(localeFile)]; + for (const language of langsToProcess) { const localeData = await getLocaleData(language.lang); $(document).find('[data-i18n]').each(function () { @@ -141,7 +142,7 @@ function addLanguagesToDropdown() { export function initLocales() { applyLocale(); addLanguagesToDropdown(); - updateSecretDisplay(); + updateSecretDisplay(); $('#ui_language_select').on('change', async function () { const language = String($(this).val()); diff --git a/public/scripts/secrets.js b/public/scripts/secrets.js index f925f52bc..00c322353 100644 --- a/public/scripts/secrets.js +++ b/public/scripts/secrets.js @@ -65,8 +65,8 @@ async function clearSecret() { export function updateSecretDisplay() { for (const [secret_key, input_selector] of Object.entries(INPUT_MAP)) { const validSecret = !!secret_state[secret_key]; - - const placeholder = $('#viewSecrets').attr(validSecret ? 'key_saved_text' : 'missing_key_text'); + + const placeholder = $('#viewSecrets').attr(validSecret ? 'key_saved_text' : 'missing_key_text'); $(input_selector).attr('placeholder', placeholder); } }