i18n.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import i18n from 'i18next'
  2. import { initReactI18next } from 'react-i18next'
  3. const LANG = window.i18n.currentLangCode
  4. // Since we are rendering React from Angular, the initialisation is
  5. // synchronous on page load (but hidden behind the loading screen). This
  6. // means that translations must be initialised without any actual
  7. // translations strings, and load those manually ourselves later
  8. i18n.use(initReactI18next).init({
  9. lng: LANG,
  10. react: {
  11. // Since we are manually waiting on the translations data to
  12. // load, we don't need to use Suspense
  13. useSuspense: false
  14. },
  15. interpolation: {
  16. // We use the legacy v1 JSON format, so configure interpolator to use
  17. // underscores instead of curly braces
  18. prefix: '__',
  19. suffix: '__',
  20. unescapeSuffix: 'HTML',
  21. // Disable nesting in interpolated values, preventing user input
  22. // injection via another nested value
  23. skipOnVariables: true
  24. }
  25. })
  26. // The webpackChunkName here will name this chunk (and thus the requested
  27. // script) according to the file name. See https://webpack.js.org/api/module-methods/#magic-comments
  28. // for details
  29. const localesPromise = import(/* webpackChunkName: "[request]" */ `../../locales/${LANG}.json`).then(
  30. lang => {
  31. i18n.addResourceBundle(LANG, 'translation', lang)
  32. }
  33. )
  34. export default localesPromise