All files / client i18n.ts

0% Statements 0/8
0% Branches 0/6
0% Functions 0/3
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                                                                       
import i18n from 'i18next'
import LngDetector from 'i18next-browser-languagedetector'
import { initReactI18next } from 'react-i18next'
 
import en from 'locales/en/translation.yml'
import ja from 'locales/ja/translation.yml'
 
export default () => {
  const lngDetector = new LngDetector()
  lngDetector.addDetector({
    name: 'userSetting',
    lookup(options) {
      const userContextHydrate = document.getElementById('user-context-hydrate')
      const textContent = userContextHydrate ? userContextHydrate.textContent || '{}' : '{}'
      const { config = {} } = JSON.parse(textContent)
      const { lang = null } = config
      return lang
    },
    cacheUserLanguage(lng, options) {},
  })
 
  i18n
    .use(lngDetector)
    .use(initReactI18next)
    .init({
      fallbackLng: 'en',
      debug: process.env.NODE_ENV === 'development',
      interpolation: { escapeValue: false },
      react: {
        wait: false,
        bindI18n: 'languageChanged loaded',
        bindStore: 'added removed',
        nsMode: 'default',
      },
      resources: {
        en: { translation: en },
        ja: { translation: ja },
      },
      detection: {
        order: ['userSetting', 'querystring', 'cookie', 'localStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
      },
    })
}