Switch to nested object pluralisation format for i18n files (#11412)

This commit is contained in:
Michael Telatynski 2023-08-16 20:08:54 +01:00 committed by GitHub
parent 523e691136
commit aee6247ad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 11874 additions and 6240 deletions

View file

@ -22,7 +22,9 @@ import de from "../../src/i18n/strings/de_DE.json";
const lv = {
"Save": "Saglabāt",
"Uploading %(filename)s and %(count)s others|one": "Качване на %(filename)s и %(count)s друг",
"Uploading %(filename)s and %(count)s others": {
one: "Качване на %(filename)s и %(count)s друг",
},
};
// Fake languages.json containing references to en_EN, de_DE and lv
@ -30,34 +32,6 @@ const lv = {
// de_DE.json
// lv.json - mock version with few translations, used to test fallback translation
type Translations = Record<string, Record<string, string> | string>;
function weblateToCounterpart(inTrs: Record<string, string>): Translations {
const outTrs: Translations = {};
for (const key of Object.keys(inTrs)) {
const keyParts = key.split("|", 2);
if (keyParts.length === 2) {
let obj = outTrs[keyParts[0]];
if (obj === undefined) {
obj = outTrs[keyParts[0]] = {};
} else if (typeof obj === "string") {
// This is a transitional edge case if a string went from singular to pluralised and both still remain
// in the translation json file. Use the singular translation as `other` and merge pluralisation atop.
obj = outTrs[keyParts[0]] = {
other: inTrs[key],
};
console.warn("Found entry in i18n file in both singular and pluralised form", keyParts[0]);
}
obj[keyParts[1]] = inTrs[key];
} else {
outTrs[key] = inTrs[key];
}
}
return outTrs;
}
fetchMock
.get("/i18n/languages.json", {
en: {
@ -73,9 +47,9 @@ fetchMock
label: "Latvian",
},
})
.get("end:en_EN.json", weblateToCounterpart(en))
.get("end:de_DE.json", weblateToCounterpart(de))
.get("end:lv.json", weblateToCounterpart(lv));
.get("end:en_EN.json", en)
.get("end:de_DE.json", de)
.get("end:lv.json", lv);
languageHandler.setLanguage("en");
languageHandler.setMissingEntryGenerator((key) => key.split("|", 2)[1]);