mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
chore(i18n): cleanup i18n file (#8318)
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user