Fix slow code blocking whole component render

This commit is contained in:
Lim Chee Aun 2023-12-28 18:39:56 +08:00
parent 1765defa56
commit 88547fa403

View file

@ -8,6 +8,12 @@ const locales = [
...navigator.languages,
];
const localeTargetLanguages = localeMatch(
locales,
translationTargetLanguages.map((l) => l.code.replace('_', '-')), // The underscore will fail Intl.Locale inside `match`
'en',
);
function getTranslateTargetLanguage(fromSettings = false) {
if (fromSettings) {
const { contentTranslationTargetLanguage } = states.settings;
@ -15,11 +21,7 @@ function getTranslateTargetLanguage(fromSettings = false) {
return contentTranslationTargetLanguage;
}
}
return localeMatch(
locales,
translationTargetLanguages.map((l) => l.code.replace('_', '-')), // The underscore will fail Intl.Locale inside `match`
'en',
);
return localeTargetLanguages;
}
export default getTranslateTargetLanguage;