Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use fallback language for when translation is empty #548

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions i18n.config.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -15,24 +17,48 @@ import pt from "./locales/pt.json";
import ro from "./locales/ro.json";
import ru from "./locales/ru.json";

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 (obj[key] === "") {
obj[key] = fallback[key];
}
});
return obj;
}
kkuepper marked this conversation as resolved.
Show resolved Hide resolved

function cleanup(
locale: LocaleMessage<VueMessageType>,
fallback: LocaleMessage<VueMessageType>,
): LocaleMessage<VueMessageType> {
Object.keys(locale).forEach((key) => {
if (typeof locale[key] === "object") {
locale[key] = cleanupEmptyProperties(locale[key], fallback[key]);
}
});
return locale;
}

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,
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),
},
}));
Loading