2018-03-29 12:47:52 +00:00
|
|
|
import i18next from 'i18next'
|
|
|
|
import queryString from 'query-string'
|
|
|
|
import enTranslations from './locales/en.yaml'
|
2018-07-12 08:09:41 +00:00
|
|
|
import { getIframeOption, parseDataAttributes } from './utils'
|
2018-03-29 12:47:52 +00:00
|
|
|
|
2018-06-18 10:12:08 +00:00
|
|
|
let getFromSessionStorage = where =>
|
|
|
|
typeof sessionStorage !== 'undefined' ? sessionStorage[where] : null
|
|
|
|
|
|
|
|
let setToSessionStorage = (where, what) =>
|
|
|
|
typeof sessionStorage !== 'undefined' &&
|
|
|
|
do {
|
|
|
|
sessionStorage[where] = what
|
|
|
|
}
|
|
|
|
|
2018-04-24 16:30:16 +00:00
|
|
|
let lang =
|
|
|
|
getIframeOption('lang') ||
|
|
|
|
queryString.parse(location.search)['lang'] ||
|
2018-06-18 10:12:08 +00:00
|
|
|
parseDataAttributes(getFromSessionStorage('lang')) ||
|
2018-04-05 16:01:03 +00:00
|
|
|
'fr'
|
|
|
|
|
2018-06-18 10:12:08 +00:00
|
|
|
setToSessionStorage('lang', lang)
|
2018-04-04 10:10:34 +00:00
|
|
|
i18next.init(
|
|
|
|
{
|
2018-04-24 16:30:16 +00:00
|
|
|
debug: false,
|
2018-03-29 12:47:52 +00:00
|
|
|
lng: lang,
|
|
|
|
resources: {
|
2018-04-04 10:10:34 +00:00
|
|
|
en: {
|
|
|
|
translation: enTranslations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(err, t) => {
|
2018-07-18 13:14:55 +00:00
|
|
|
console && console.error('Error from i18n load', err, t) //eslint-disable-line no-console
|
2018-04-04 10:10:34 +00:00
|
|
|
}
|
|
|
|
)
|
2018-03-29 12:47:52 +00:00
|
|
|
|
|
|
|
export default lang
|