From 2685682f8272c40c8cb7813bf05207967fa53a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20Ku=CC=88pper?= Date: Wed, 8 Jan 2025 15:04:48 -0500 Subject: [PATCH 1/4] try using fallback language for when translation is "" --- i18n.config.ts | 17 +++++++++++++++++ locales/de.json | 10 +++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/i18n.config.ts b/i18n.config.ts index 325b771f..6d70a49b 100644 --- a/i18n.config.ts +++ b/i18n.config.ts @@ -35,4 +35,21 @@ export default defineI18nConfig(() => ({ ro, ru, }, + fallbackRootWithEmptyString: true, + postTranslation: (value, path) => { + if (value === "") { + const parts = path.split("."); + let message = en; + return "empty translation"; + for (const key of parts) { + if (key in message) { + message = message[key]; + } else { + return value; + } + } + return message; + } + return value; + }, })); diff --git a/locales/de.json b/locales/de.json index 67f736c1..97986792 100644 --- a/locales/de.json +++ b/locales/de.json @@ -5,21 +5,21 @@ }, "nav": { "home": "Start", - "browse": "Stöbern", + "browse": "", "playlist": "Playlist", "profile": "Profil", "messages": "Reden", "recent-messages": "Neue Reden", "recent-music": "Neue Musik", "audiobooks": "Hörbücher", - "search": "Suche", + "search": "", "album": "Album", "podcast": "Podcast", "not-found": "Seite nicht gefunden", "contributor": "Mitwirkender", "contributors": "Mitwirkende", "archive": "Archiv", - "transcribe": "Transkribieren", + "transcribe": "", "lyrics": "Liedtext" }, "sidebar": { @@ -66,7 +66,7 @@ }, "collection": { "track-count": "{count} Titel | {count} Titel", - "album-count": "{count} Album | {count} Alben", + "album-count": "", "resume": "Weiterhören" }, "login": { @@ -144,7 +144,7 @@ "more-info": "Weitere Informationen", "show-all": "Alle anzeigen", "remove-from-playlist": "Aus Wiedergabeliste entfernen", - "transcription": "Transkription" + "transcription": "" }, "a11y": { "download": "Herunterladen", From 322d2f42f79ee4f932f155e4f25e16d4fb0ea9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20Ku=CC=88pper?= Date: Tue, 14 Jan 2025 12:08:29 -0500 Subject: [PATCH 2/4] delete properties with "" so that fallback language is used --- i18n.config.ts | 73 ++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/i18n.config.ts b/i18n.config.ts index 6d70a49b..78aeaf89 100644 --- a/i18n.config.ts +++ b/i18n.config.ts @@ -1,3 +1,5 @@ +import type { LocaleMessage } from "@intlify/core"; +import type { VueMessageType } from "vue-i18n"; import de from "./locales/de.json"; import en from "./locales/en.json"; import nb from "./locales/nb.json"; @@ -15,41 +17,48 @@ import pt from "./locales/pt.json"; import ro from "./locales/ro.json"; import ru from "./locales/ru.json"; +function cleanupAny(existing: any, fallback: any): any { + Object.keys(existing).forEach((key) => { + if (typeof existing[key] === "object") { + existing[key] = cleanupAny(existing[key], fallback[key]); + } + if (existing[key] === "") { + existing[key] = fallback[key]; + } + }); + return existing; +} + +function cleanup( + existing: LocaleMessage, + fallback: LocaleMessage, +): LocaleMessage { + Object.keys(existing).forEach((key) => { + if (typeof existing[key] === "object") { + existing[key] = cleanupAny(existing[key], fallback[key]); + } + }); + return existing; +} + export default defineI18nConfig(() => ({ legacy: false, messages: { - nb, + nb: cleanup(nb, en), en, - de, - nl, - fr, - sl, - tr, - ta, - da, - es, - et, - fi, - hu, - pt, - ro, - ru, - }, - fallbackRootWithEmptyString: true, - postTranslation: (value, path) => { - if (value === "") { - const parts = path.split("."); - let message = en; - return "empty translation"; - for (const key of parts) { - if (key in message) { - message = message[key]; - } else { - return value; - } - } - return message; - } - return value; + de: cleanup(de, en), + nl: cleanup(nl, en), + fr: cleanup(fr, en), + sl: cleanup(sl, en), + tr: cleanup(tr, en), + ta: cleanup(ta, en), + da: cleanup(da, en), + es: cleanup(es, en), + et: cleanup(et, en), + fi: cleanup(fi, en), + hu: cleanup(hu, en), + pt: cleanup(pt, en), + ro: cleanup(ro, en), + ru: cleanup(ru, en), }, })); From 43e41ac814d75f66c861e4aa3691887a0d179ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20Ku=CC=88pper?= Date: Tue, 14 Jan 2025 12:12:25 -0500 Subject: [PATCH 3/4] revert test data --- locales/de.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/locales/de.json b/locales/de.json index 97986792..67f736c1 100644 --- a/locales/de.json +++ b/locales/de.json @@ -5,21 +5,21 @@ }, "nav": { "home": "Start", - "browse": "", + "browse": "Stöbern", "playlist": "Playlist", "profile": "Profil", "messages": "Reden", "recent-messages": "Neue Reden", "recent-music": "Neue Musik", "audiobooks": "Hörbücher", - "search": "", + "search": "Suche", "album": "Album", "podcast": "Podcast", "not-found": "Seite nicht gefunden", "contributor": "Mitwirkender", "contributors": "Mitwirkende", "archive": "Archiv", - "transcribe": "", + "transcribe": "Transkribieren", "lyrics": "Liedtext" }, "sidebar": { @@ -66,7 +66,7 @@ }, "collection": { "track-count": "{count} Titel | {count} Titel", - "album-count": "", + "album-count": "{count} Album | {count} Alben", "resume": "Weiterhören" }, "login": { @@ -144,7 +144,7 @@ "more-info": "Weitere Informationen", "show-all": "Alle anzeigen", "remove-from-playlist": "Aus Wiedergabeliste entfernen", - "transcription": "" + "transcription": "Transkription" }, "a11y": { "download": "Herunterladen", From f15efb5d19b5f3a03f1a34b6c7ecaf6a36b13d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20Ku=CC=88pper?= Date: Tue, 14 Jan 2025 12:25:46 -0500 Subject: [PATCH 4/4] refactor --- i18n.config.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/i18n.config.ts b/i18n.config.ts index 78aeaf89..32c27676 100644 --- a/i18n.config.ts +++ b/i18n.config.ts @@ -17,28 +17,28 @@ import pt from "./locales/pt.json"; import ro from "./locales/ro.json"; import ru from "./locales/ru.json"; -function cleanupAny(existing: any, fallback: any): any { - Object.keys(existing).forEach((key) => { - if (typeof existing[key] === "object") { - existing[key] = cleanupAny(existing[key], fallback[key]); +function cleanupEmptyProperties(obj: any, fallback: any): any { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === "object") { + obj[key] = cleanupEmptyProperties(obj[key], fallback[key]); } - if (existing[key] === "") { - existing[key] = fallback[key]; + if (obj[key] === "") { + obj[key] = fallback[key]; } }); - return existing; + return obj; } function cleanup( - existing: LocaleMessage, + locale: LocaleMessage, fallback: LocaleMessage, ): LocaleMessage { - Object.keys(existing).forEach((key) => { - if (typeof existing[key] === "object") { - existing[key] = cleanupAny(existing[key], fallback[key]); + Object.keys(locale).forEach((key) => { + if (typeof locale[key] === "object") { + locale[key] = cleanupEmptyProperties(locale[key], fallback[key]); } }); - return existing; + return locale; } export default defineI18nConfig(() => ({