index.ts 2.8 KB

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