2020-09-03 09:23:34 +00:00
|
|
|
import i18n from 'i18next'
|
|
|
|
import { initReactI18next } from 'react-i18next'
|
|
|
|
|
|
|
|
const LANG = window.i18n.currentLangCode
|
|
|
|
|
|
|
|
// Since we are rendering React from Angular, the initialisation is
|
|
|
|
// synchronous on page load (but hidden behind the loading screen). This
|
|
|
|
// means that translations must be initialised without any actual
|
2021-01-21 12:21:28 +00:00
|
|
|
// translation strings, and load those manually ourselves later
|
2020-09-03 09:23:34 +00:00
|
|
|
|
|
|
|
i18n.use(initReactI18next).init({
|
|
|
|
lng: LANG,
|
|
|
|
|
|
|
|
react: {
|
|
|
|
// Since we are manually waiting on the translations data to
|
|
|
|
// load, we don't need to use Suspense
|
2021-01-21 12:21:28 +00:00
|
|
|
useSuspense: false,
|
|
|
|
|
|
|
|
// Trigger a re-render when a language is added. Since we load the
|
|
|
|
// translation strings asynchronously, we need to trigger a re-render once
|
|
|
|
// they've loaded
|
2021-04-27 07:52:58 +00:00
|
|
|
bindI18nStore: 'added',
|
2020-09-03 09:23:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
interpolation: {
|
|
|
|
// We use the legacy v1 JSON format, so configure interpolator to use
|
|
|
|
// underscores instead of curly braces
|
|
|
|
prefix: '__',
|
|
|
|
suffix: '__',
|
|
|
|
unescapeSuffix: 'HTML',
|
|
|
|
|
|
|
|
// Disable nesting in interpolated values, preventing user input
|
|
|
|
// injection via another nested value
|
2021-03-25 10:11:31 +00:00
|
|
|
skipOnVariables: true,
|
|
|
|
|
|
|
|
defaultVariables: {
|
2021-04-27 07:52:58 +00:00
|
|
|
appName: window.ExposedSettings.appName,
|
|
|
|
},
|
|
|
|
},
|
2020-09-03 09:23:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// The webpackChunkName here will name this chunk (and thus the requested
|
|
|
|
// script) according to the file name. See https://webpack.js.org/api/module-methods/#magic-comments
|
|
|
|
// for details
|
2020-12-15 10:23:54 +00:00
|
|
|
const localesPromise = import(
|
|
|
|
/* webpackChunkName: "[request]" */ `../../locales/${LANG}.json`
|
|
|
|
).then(lang => {
|
|
|
|
i18n.addResourceBundle(LANG, 'translation', lang)
|
|
|
|
})
|
2020-09-03 09:23:34 +00:00
|
|
|
|
|
|
|
export default localesPromise
|