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