From 88547fa4035af346757f87cd1460f9ce9aa5d813 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 28 Dec 2023 18:39:56 +0800 Subject: [PATCH] Fix slow code blocking whole component render --- src/utils/get-translate-target-language.jsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/utils/get-translate-target-language.jsx b/src/utils/get-translate-target-language.jsx index 5a3d6b02..9fcc9568 100644 --- a/src/utils/get-translate-target-language.jsx +++ b/src/utils/get-translate-target-language.jsx @@ -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;