From 8cd3e38f221ef250c09de7c77eec8cd79f171aa9 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 4 Oct 2023 10:19:28 +0800 Subject: [PATCH] Move this up, Intl stuff seems to run slow sometimes --- src/utils/get-translate-target-language.jsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utils/get-translate-target-language.jsx b/src/utils/get-translate-target-language.jsx index 7a598643..5a3d6b02 100644 --- a/src/utils/get-translate-target-language.jsx +++ b/src/utils/get-translate-target-language.jsx @@ -3,6 +3,11 @@ import translationTargetLanguages from '../data/lingva-target-languages'; import localeMatch from './locale-match'; import states from './states'; +const locales = [ + new Intl.DateTimeFormat().resolvedOptions().locale, + ...navigator.languages, +]; + function getTranslateTargetLanguage(fromSettings = false) { if (fromSettings) { const { contentTranslationTargetLanguage } = states.settings; @@ -11,10 +16,7 @@ function getTranslateTargetLanguage(fromSettings = false) { } } return localeMatch( - [ - new Intl.DateTimeFormat().resolvedOptions().locale, - ...navigator.languages, - ], + locales, translationTargetLanguages.map((l) => l.code.replace('_', '-')), // The underscore will fail Intl.Locale inside `match` 'en', );