chore(i18n): cleanup i18n file (#8318)

This commit is contained in:
EYHN
2024-09-20 06:25:17 +00:00
parent bed70cd51a
commit 096f50b83b
12 changed files with 110 additions and 444 deletions

View File

@@ -98,3 +98,25 @@ export function setUpLanguage(i: i18n) {
}
return i.changeLanguage(language);
}
const cachedCompleteness: Record<string, number> = {};
export const calcLocaleCompleteness = (
locale: (typeof LOCALES)[number]['tag']
) => {
if (cachedCompleteness[locale]) {
return cachedCompleteness[locale];
}
const base = LOCALES.find(item => item.base);
if (!base) {
throw new Error('Base language not found');
}
const target = LOCALES.find(item => item.tag === locale);
if (!target) {
throw new Error('Locale not found');
}
const baseKeyCount = Object.keys(base.res).length;
const translatedKeyCount = Object.keys(target.res).length;
const completeness = translatedKeyCount / baseKeyCount;
cachedCompleteness[target.tag] = completeness;
return completeness;
};