2020-11-20 14:21:31 +01:00
|
|
|
import homepages from 'homepages';
|
2021-04-06 21:15:08 +02:00
|
|
|
import SUPPORTED_BROWSER_LANGUAGES from 'constants/supported_browser_languages';
|
2020-11-20 14:21:31 +01:00
|
|
|
const DEFAULT_LANG = 'en';
|
|
|
|
|
2021-01-06 19:13:56 +01:00
|
|
|
export const getDefaultLanguage = () => {
|
2021-04-06 21:15:08 +02:00
|
|
|
const browserLanguage = window.navigator.language;
|
|
|
|
return SUPPORTED_BROWSER_LANGUAGES[browserLanguage] || DEFAULT_LANG;
|
2020-11-20 14:21:31 +01:00
|
|
|
};
|
|
|
|
|
2021-01-06 19:13:56 +01:00
|
|
|
// If homepages has a key "zh-Hant" return that, otherwise return "zh", otherwise "en"
|
|
|
|
export const getDefaultHomepageKey = () => {
|
|
|
|
const language = getDefaultLanguage();
|
|
|
|
return (homepages[language] && language) || (homepages[language.slice(0, 2)] && language.slice(0, 2)) || DEFAULT_LANG;
|
2020-11-20 14:21:31 +01:00
|
|
|
};
|