index.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import indexEn from './en/index';
  22. import indexCn from './cn/index';
  23. import insertEn from './en/insert';
  24. import insertCn from './cn/insert';
  25. import searchEn from './en/search';
  26. import searchCn from './cn/search';
  27. import systemViewTransEn from './en/systemView';
  28. import systemViewTransCn from './cn/systemView';
  29. export const resources = {
  30. cn: {
  31. translation: commonCn,
  32. btn: buttonCn,
  33. warning: warningCn,
  34. nav: navCn,
  35. overview: overviewCn,
  36. collection: collectionCn,
  37. dialog: dialogCn,
  38. partition: partitionCn,
  39. success: successCn,
  40. index: indexCn,
  41. insert: insertCn,
  42. search: searchCn,
  43. systemView: systemViewTransCn,
  44. },
  45. en: {
  46. translation: commonEn,
  47. btn: buttonEn,
  48. warning: warningEn,
  49. nav: navEn,
  50. overview: overviewEn,
  51. collection: collectionEn,
  52. dialog: dialogEn,
  53. partition: partitionEn,
  54. success: successEn,
  55. index: indexEn,
  56. insert: insertEn,
  57. search: searchEn,
  58. systemView: systemViewTransEn
  59. },
  60. };
  61. // the translations
  62. // (tip move them in a JSON file and import them)
  63. i18n
  64. // detect user language
  65. // learn more: https://github.com/i18next/i18next-browser-languageDetector
  66. // .use(LanguageDetector)
  67. .use(initReactI18next) // passes i18n down to react-i18next
  68. .init({
  69. lng: 'en',
  70. fallbackLng: 'en',
  71. resources,
  72. keySeparator: false, // we do not use keys in form messages.welcome
  73. returnObjects: true,
  74. interpolation: {
  75. escapeValue: false, // react already safes from xss
  76. },
  77. detection: {
  78. // order and from where user language should be detected
  79. order: ['localStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
  80. // keys or params to lookup language from
  81. lookupLocalStorage: 'lang',
  82. lookupFromPathIndex: 0,
  83. lookupFromSubdomainIndex: 0,
  84. // cache user language on
  85. caches: ['localStorage', 'cookie'],
  86. excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)
  87. // optional expire and domain for set cookie
  88. cookieMinutes: 10,
  89. cookieDomain: 'myDomain',
  90. // optional htmlTag with lang attribute, the default is:
  91. htmlTag: document.documentElement,
  92. // only detect languages that are in the whitelist
  93. checkWhitelist: true,
  94. },
  95. });
  96. export default i18n;