2018-03-29 14:47:52 +02:00
|
|
|
import i18next from 'i18next'
|
2019-02-08 12:45:14 +01:00
|
|
|
import { initReactI18next } from 'react-i18next'
|
2018-03-29 14:47:52 +02:00
|
|
|
import enTranslations from './locales/en.yaml'
|
2019-10-12 20:23:54 +02:00
|
|
|
import unitsTranslations from './locales/units.yaml'
|
2019-10-16 19:24:47 +02:00
|
|
|
import { getSessionStorage } from './utils'
|
2018-06-18 12:12:08 +02:00
|
|
|
|
2019-11-10 16:57:44 +01:00
|
|
|
export type AvailableLangs = 'fr' | 'en'
|
|
|
|
|
2018-04-24 18:30:16 +02:00
|
|
|
let lang =
|
2019-10-18 19:15:58 +02:00
|
|
|
(typeof document !== 'undefined' &&
|
|
|
|
new URLSearchParams(document.location.search.substring(1)).get('lang')) ||
|
2019-10-16 19:24:47 +02:00
|
|
|
getSessionStorage()
|
|
|
|
?.getItem('lang')
|
|
|
|
?.match(/^(fr|en)$/)?.[0] ||
|
2018-04-05 18:01:03 +02:00
|
|
|
'fr'
|
|
|
|
|
2019-10-16 19:24:47 +02:00
|
|
|
getSessionStorage()?.setItem('lang', lang)
|
2019-10-12 18:45:55 +02:00
|
|
|
i18next
|
|
|
|
.use(initReactI18next)
|
|
|
|
.init({
|
2018-03-29 14:47:52 +02:00
|
|
|
lng: lang,
|
|
|
|
resources: {
|
2019-10-12 20:23:54 +02:00
|
|
|
fr: { units: unitsTranslations.fr },
|
2018-04-04 12:10:34 +02:00
|
|
|
en: {
|
2019-10-12 20:23:54 +02:00
|
|
|
translation: enTranslations,
|
|
|
|
units: unitsTranslations.en
|
2018-04-04 12:10:34 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-12 18:45:55 +02:00
|
|
|
})
|
|
|
|
.catch(err => console?.error('Error from i18n load', err))
|
2018-03-29 14:47:52 +02:00
|
|
|
|
2018-11-09 12:36:29 +01:00
|
|
|
export default i18next
|