2023-03-07 17:38:06 +03:00
|
|
|
import translationTargetLanguages from '../data/lingva-target-languages';
|
|
|
|
|
2023-05-20 09:14:35 +03:00
|
|
|
import localeMatch from './locale-match';
|
2023-03-07 17:38:06 +03:00
|
|
|
import states from './states';
|
|
|
|
|
2023-10-04 05:19:28 +03:00
|
|
|
const locales = [
|
|
|
|
new Intl.DateTimeFormat().resolvedOptions().locale,
|
|
|
|
...navigator.languages,
|
|
|
|
];
|
|
|
|
|
2023-03-07 17:38:06 +03:00
|
|
|
function getTranslateTargetLanguage(fromSettings = false) {
|
|
|
|
if (fromSettings) {
|
|
|
|
const { contentTranslationTargetLanguage } = states.settings;
|
|
|
|
if (contentTranslationTargetLanguage) {
|
|
|
|
return contentTranslationTargetLanguage;
|
|
|
|
}
|
|
|
|
}
|
2023-05-20 09:14:35 +03:00
|
|
|
return localeMatch(
|
2023-10-04 05:19:28 +03:00
|
|
|
locales,
|
2023-03-07 17:38:06 +03:00
|
|
|
translationTargetLanguages.map((l) => l.code.replace('_', '-')), // The underscore will fail Intl.Locale inside `match`
|
|
|
|
'en',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default getTranslateTargetLanguage;
|