Update weblateToCounterpart to be more resilient (#8633)

* Remove unused code for weblate->counterpart conversion

Happens at build time instead now

* Update `weblateToCounterpart` to be more resilient
This commit is contained in:
Michael Telatynski 2022-05-17 17:44:29 +01:00 committed by GitHub
parent d9b7e0721c
commit 118585a672
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 28 deletions

View file

@ -556,27 +556,13 @@ function getLangsJson(): Promise<object> {
});
}
function weblateToCounterpart(inTrs: object): object {
const outTrs = {};
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]] = obj;
}
obj[keyParts[1]] = inTrs[key];
} else {
outTrs[key] = inTrs[key];
}
}
return outTrs;
interface ICounterpartTranslation {
[key: string]: string | {
[pluralisation: string]: string;
};
}
async function getLanguageRetry(langPath: string, num = 3): Promise<object> {
async function getLanguageRetry(langPath: string, num = 3): Promise<ICounterpartTranslation> {
return retry(() => getLanguage(langPath), num, e => {
logger.log("Failed to load i18n", langPath);
logger.error(e);
@ -584,7 +570,7 @@ async function getLanguageRetry(langPath: string, num = 3): Promise<object> {
});
}
function getLanguage(langPath: string): Promise<object> {
function getLanguage(langPath: string): Promise<ICounterpartTranslation> {
return new Promise((resolve, reject) => {
request(
{ method: "GET", url: langPath },
@ -597,7 +583,7 @@ function getLanguage(langPath: string): Promise<object> {
reject(new Error(`Failed to load ${langPath}, got ${response.status}`));
return;
}
resolve(weblateToCounterpart(JSON.parse(body)));
resolve(JSON.parse(body));
},
);
});