index.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import i18n from 'i18next';
  2. import { initReactI18next } from 'react-i18next';
  3. import commonCn from './cn/common';
  4. import commonEn from './en/common';
  5. import buttonEn from './en/button';
  6. import buttonCn from './cn/button';
  7. import warningCn from './cn/warning';
  8. import warningEn from './en/warning';
  9. import navCn from './cn/nav';
  10. import navEn from './en/nav';
  11. import overviewCn from './cn/overview';
  12. import overviewEn from './en/overview';
  13. import collectionCn from './cn/collection';
  14. import collectionEn from './en/collection';
  15. import dialogCn from './cn/dialog';
  16. import dialogEn from './en/dialog';
  17. import partitionCn from './cn/partition';
  18. import partitionEn from './en/partition';
  19. import successEn from './en/success';
  20. import successCn from './cn/success';
  21. export const resources = {
  22. cn: {
  23. translation: commonCn,
  24. btn: buttonCn,
  25. warning: warningCn,
  26. nav: navCn,
  27. overview: overviewCn,
  28. collection: collectionCn,
  29. dialog: dialogCn,
  30. partition: partitionCn,
  31. success: successCn,
  32. },
  33. en: {
  34. translation: commonEn,
  35. btn: buttonEn,
  36. warning: warningEn,
  37. nav: navEn,
  38. overview: overviewEn,
  39. collection: collectionEn,
  40. dialog: dialogEn,
  41. partition: partitionEn,
  42. success: successEn,
  43. },
  44. };
  45. // the translations
  46. // (tip move them in a JSON file and import them)
  47. i18n
  48. // detect user language
  49. // learn more: https://github.com/i18next/i18next-browser-languageDetector
  50. // .use(LanguageDetector)
  51. .use(initReactI18next) // passes i18n down to react-i18next
  52. .init({
  53. lng: 'en',
  54. fallbackLng: 'en',
  55. resources,
  56. keySeparator: false, // we do not use keys in form messages.welcome
  57. returnObjects: true,
  58. interpolation: {
  59. escapeValue: false, // react already safes from xss
  60. },
  61. detection: {
  62. // order and from where user language should be detected
  63. order: ['localStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
  64. // keys or params to lookup language from
  65. lookupLocalStorage: 'lang',
  66. lookupFromPathIndex: 0,
  67. lookupFromSubdomainIndex: 0,
  68. // cache user language on
  69. caches: ['localStorage', 'cookie'],
  70. excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)
  71. // optional expire and domain for set cookie
  72. cookieMinutes: 10,
  73. cookieDomain: 'myDomain',
  74. // optional htmlTag with lang attribute, the default is:
  75. htmlTag: document.documentElement,
  76. // only detect languages that are in the whitelist
  77. checkWhitelist: true,
  78. },
  79. });
  80. export default i18n;