2019-03-12 11:22:59 +00:00
|
|
|
import { LANGUAGE } from 'config/app';
|
2019-02-18 11:49:27 +00:00
|
|
|
|
2019-04-12 15:24:11 +00:00
|
|
|
export const getInitialLocale = (navigatorLanguage, defaultLocale = 'en') => {
|
|
|
|
if (!navigatorLanguage) return defaultLocale;
|
|
|
|
|
|
|
|
const browserLocale = navigatorLanguage.split('-')[0];
|
2019-02-18 11:49:27 +00:00
|
|
|
if (LANGUAGE.some(e => e.code === browserLocale)) {
|
|
|
|
// Array of supported languages contains the locale we're looking for
|
|
|
|
return browserLocale;
|
|
|
|
}
|
|
|
|
// if browser lang is not supported return en as default locale
|
|
|
|
return defaultLocale;
|
2019-03-04 12:33:02 +00:00
|
|
|
};
|