github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/ui/src/i18n.ts (about)

     1  import i18n from 'i18next'
     2  import { initReactI18next } from 'react-i18next'
     3  import LanguageDetector from 'i18next-browser-languagedetector'
     4  
     5  const translations = import.meta.globEager('../locales/*.json')
     6  
     7  const resources = Object.keys(translations).reduce(
     8    (acc: Record<string, any>, path) => {
     9      const name = path.split('/').pop()?.replace('.json', '')
    10      if (name) {
    11        acc[name] = {
    12          translation: translations[path].default,
    13        }
    14      }
    15      return acc
    16    },
    17    {}
    18  )
    19  
    20  const i18nextOptions = {
    21    lng: JSON.parse(localStorage.getItem('lang') ?? 'null') || 'en',
    22    fallbackLng: 'en',
    23    interpolation: {
    24      escapeValue: false,
    25    },
    26    resources,
    27  }
    28  
    29  i18n.use(LanguageDetector).use(initReactI18next).init(i18nextOptions)
    30  
    31  export default i18n