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 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',
);