i18next-config.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use client'
  2. import i18n from 'i18next'
  3. import { initReactI18next } from 'react-i18next'
  4. import { LanguagesSupported } from '@/i18n/language'
  5. const loadLangResources = (lang: string) => ({
  6. translation: {
  7. common: require(`./${lang}/common`).default,
  8. layout: require(`./${lang}/layout`).default,
  9. login: require(`./${lang}/login`).default,
  10. register: require(`./${lang}/register`).default,
  11. app: require(`./${lang}/app`).default,
  12. appOverview: require(`./${lang}/app-overview`).default,
  13. appDebug: require(`./${lang}/app-debug`).default,
  14. appApi: require(`./${lang}/app-api`).default,
  15. appLog: require(`./${lang}/app-log`).default,
  16. appAnnotation: require(`./${lang}/app-annotation`).default,
  17. share: require(`./${lang}/share-app`).default,
  18. dataset: require(`./${lang}/dataset`).default,
  19. datasetDocuments: require(`./${lang}/dataset-documents`).default,
  20. datasetHitTesting: require(`./${lang}/dataset-hit-testing`).default,
  21. datasetSettings: require(`./${lang}/dataset-settings`).default,
  22. datasetCreation: require(`./${lang}/dataset-creation`).default,
  23. explore: require(`./${lang}/explore`).default,
  24. billing: require(`./${lang}/billing`).default,
  25. custom: require(`./${lang}/custom`).default,
  26. tools: require(`./${lang}/tools`).default,
  27. workflow: require(`./${lang}/workflow`).default,
  28. runLog: require(`./${lang}/run-log`).default,
  29. },
  30. })
  31. // Automatically generate the resources object
  32. const resources = LanguagesSupported.reduce((acc: any, lang: string) => {
  33. acc[lang] = loadLangResources(lang)
  34. return acc
  35. }, {})
  36. i18n.use(initReactI18next)
  37. .init({
  38. lng: undefined,
  39. fallbackLng: 'en-US',
  40. resources,
  41. })
  42. export const changeLanguage = i18n.changeLanguage
  43. export default i18n