31 lines
751 B
JavaScript
31 lines
751 B
JavaScript
import i18next from 'i18next'
|
|
import { initReactI18next } from 'react-i18next'
|
|
import enTranslations from './locales/en.yaml'
|
|
import unitsTranslations from './locales/units.yaml'
|
|
import { getSessionStorage } from './utils'
|
|
|
|
let lang =
|
|
(typeof document !== 'undefined' &&
|
|
new URLSearchParams(document.location.search.substring(1)).get('lang')) ||
|
|
getSessionStorage()
|
|
?.getItem('lang')
|
|
?.match(/^(fr|en)$/)?.[0] ||
|
|
'fr'
|
|
|
|
getSessionStorage()?.setItem('lang', lang)
|
|
i18next
|
|
.use(initReactI18next)
|
|
.init({
|
|
lng: lang,
|
|
resources: {
|
|
fr: { units: unitsTranslations.fr },
|
|
en: {
|
|
translation: enTranslations,
|
|
units: unitsTranslations.en
|
|
}
|
|
}
|
|
})
|
|
.catch(err => console?.error('Error from i18n load', err))
|
|
|
|
export default i18next
|