Move this up, Intl stuff seems to run slow sometimes

pull/251/head
Lim Chee Aun 2023-10-04 10:19:28 +08:00
rodzic be964f933c
commit 8cd3e38f22
1 zmienionych plików z 6 dodań i 4 usunięć

Wyświetl plik

@ -3,6 +3,11 @@ import translationTargetLanguages from '../data/lingva-target-languages';
import localeMatch from './locale-match'; import localeMatch from './locale-match';
import states from './states'; import states from './states';
const locales = [
new Intl.DateTimeFormat().resolvedOptions().locale,
...navigator.languages,
];
function getTranslateTargetLanguage(fromSettings = false) { function getTranslateTargetLanguage(fromSettings = false) {
if (fromSettings) { if (fromSettings) {
const { contentTranslationTargetLanguage } = states.settings; const { contentTranslationTargetLanguage } = states.settings;
@ -11,10 +16,7 @@ function getTranslateTargetLanguage(fromSettings = false) {
} }
} }
return localeMatch( return localeMatch(
[ locales,
new Intl.DateTimeFormat().resolvedOptions().locale,
...navigator.languages,
],
translationTargetLanguages.map((l) => l.code.replace('_', '-')), // The underscore will fail Intl.Locale inside `match` translationTargetLanguages.map((l) => l.code.replace('_', '-')), // The underscore will fail Intl.Locale inside `match`
'en', 'en',
); );