From e594e1b44d14ad25bda13efd78f37c30f679c440 Mon Sep 17 00:00:00 2001 From: Liam Keegan Date: Fri, 13 Dec 2024 08:53:21 +0100 Subject: [PATCH] Fix bug in admin translation editing (#207) - ensure that all sections from de are present in each translation - if a section is missing then add it - we don't need to add missing keys as they are created automatically - resolves #206 --- frontend/src/lib/components/Admin/Translations.svelte | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/components/Admin/Translations.svelte b/frontend/src/lib/components/Admin/Translations.svelte index 3cedc5ca..3d179bc3 100644 --- a/frontend/src/lib/components/Admin/Translations.svelte +++ b/frontend/src/lib/components/Admin/Translations.svelte @@ -20,10 +20,19 @@ import de from "../../../locales/de.json"; type Translation = Record>; let translations = $state({} as Record); +function fillMissingSections(translation: Translation): Translation { + for (const section_key in de) { + if (!(section_key in translation)) { + translation[section_key] = {}; + } + } + return translation; +} + async function refreshTranslations() { for (const lang_id of $locales) { if (lang_id !== "de") { - translations[lang_id] = await getI18nJson(lang_id); + translations[lang_id] = fillMissingSections(await getI18nJson(lang_id)); } } }