2020-09-03 05:23:34 -04:00
|
|
|
import i18n from 'i18next'
|
|
|
|
import { initReactI18next } from 'react-i18next'
|
2024-06-18 06:01:37 -04:00
|
|
|
import getMeta from '@/utils/meta'
|
2020-09-03 05:23:34 -04:00
|
|
|
|
2024-06-18 06:01:37 -04:00
|
|
|
const LANG = getMeta('ol-i18n').currentLangCode
|
2020-09-03 05:23:34 -04:00
|
|
|
|
|
|
|
// 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 07:21:28 -05:00
|
|
|
// translation strings, and load those manually ourselves later
|
2020-09-03 05:23:34 -04:00
|
|
|
|
|
|
|
i18n.use(initReactI18next).init({
|
|
|
|
lng: LANG,
|
|
|
|
|
2023-10-20 06:16:43 -04:00
|
|
|
// still using the v3 plural suffixes
|
|
|
|
compatibilityJSON: 'v3',
|
|
|
|
|
2020-09-03 05:23:34 -04:00
|
|
|
react: {
|
|
|
|
// Since we are manually waiting on the translations data to
|
|
|
|
// load, we don't need to use Suspense
|
2021-01-21 07:21:28 -05: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 03:52:58 -04:00
|
|
|
bindI18nStore: 'added',
|
2023-10-30 06:29:56 -04:00
|
|
|
|
|
|
|
// Disable automatic conversion of basic markup to React components
|
|
|
|
transSupportBasicHtmlNodes: false,
|
2020-09-03 05:23:34 -04: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 06:11:31 -04:00
|
|
|
skipOnVariables: true,
|
|
|
|
|
2023-10-19 04:27:45 -04:00
|
|
|
// Do not escape values, as `t` + React will already escape them
|
|
|
|
// (`escapeValue: true` and `shouldUnescape` must be set on each use of `Trans`)
|
|
|
|
escapeValue: false,
|
|
|
|
|
2021-03-25 06:11:31 -04:00
|
|
|
defaultVariables: {
|
2024-06-18 06:01:37 -04:00
|
|
|
appName: getMeta('ol-ExposedSettings').appName,
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
|
|
|
},
|
2020-09-03 05:23:34 -04: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 05:23:54 -05:00
|
|
|
const localesPromise = import(
|
|
|
|
/* webpackChunkName: "[request]" */ `../../locales/${LANG}.json`
|
|
|
|
).then(lang => {
|
|
|
|
i18n.addResourceBundle(LANG, 'translation', lang)
|
|
|
|
})
|
2020-09-03 05:23:34 -04:00
|
|
|
|
|
|
|
export default localesPromise
|