index.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import i18n from 'i18next';
  2. import { initReactI18next } from 'react-i18next';
  3. import LanguageDetector from 'i18next-browser-languagedetector';
  4. import commonCn from './cn/common';
  5. import commonEn from './en/common';
  6. import buttonEn from './en/button';
  7. import buttonCn from './cn/button';
  8. import warningCn from './cn/warning';
  9. import warningEn from './en/warning';
  10. import navCn from './cn/nav';
  11. import navEn from './en/nav';
  12. import homeCn from './cn/home';
  13. import homeEn from './en/home';
  14. import collectionCn from './cn/collection';
  15. import collectionEn from './en/collection';
  16. import dialogCn from './cn/dialog';
  17. import dialogEn from './en/dialog';
  18. import partitionCn from './cn/partition';
  19. import partitionEn from './en/partition';
  20. import successEn from './en/success';
  21. import successCn from './cn/success';
  22. import indexEn from './en/index';
  23. import indexCn from './cn/index';
  24. import insertEn from './en/insert';
  25. import insertCn from './cn/insert';
  26. import searchEn from './en/search';
  27. import searchCn from './cn/search';
  28. import systemViewTransEn from './en/systemView';
  29. import systemViewTransCn from './cn/systemView';
  30. import userTransEn from './en/user';
  31. import userTransCn from './cn/user';
  32. import databaseTransEn from './en/database';
  33. import databaseTransCn from './cn/database';
  34. import prometheusTransEn from './en/prometheus';
  35. import prometheusTransCn from './cn/prometheus';
  36. import propertiesEn from './en/properties';
  37. import propertiesCn from './cn/properties';
  38. export const resources = {
  39. 'zh-CN': {
  40. translation: commonCn,
  41. btn: buttonCn,
  42. warning: warningCn,
  43. nav: navCn,
  44. home: homeCn,
  45. collection: collectionCn,
  46. dialog: dialogCn,
  47. partition: partitionCn,
  48. success: successCn,
  49. index: indexCn,
  50. insert: insertCn,
  51. search: searchCn,
  52. systemView: systemViewTransCn,
  53. user: userTransCn,
  54. database: databaseTransCn,
  55. prometheus: prometheusTransCn,
  56. properties: propertiesCn,
  57. },
  58. en: {
  59. translation: commonEn,
  60. btn: buttonEn,
  61. warning: warningEn,
  62. nav: navEn,
  63. home: homeEn,
  64. collection: collectionEn,
  65. dialog: dialogEn,
  66. partition: partitionEn,
  67. success: successEn,
  68. index: indexEn,
  69. insert: insertEn,
  70. search: searchEn,
  71. systemView: systemViewTransEn,
  72. user: userTransEn,
  73. database: databaseTransEn,
  74. prometheus: prometheusTransEn,
  75. properties: propertiesEn,
  76. },
  77. };
  78. // the translations
  79. // (tip move them in a JSON file and import them)
  80. i18n
  81. // detect user language
  82. // learn more: https://github.com/i18next/i18next-browser-languageDetector
  83. .use(LanguageDetector)
  84. .use(initReactI18next) // passes i18n down to react-i18next
  85. .init({
  86. fallbackLng: 'en',
  87. resources,
  88. keySeparator: false, // we do not use keys in form messages.welcome
  89. returnObjects: true,
  90. interpolation: {
  91. escapeValue: false, // react already safes from xss
  92. },
  93. detection: {
  94. // order and from where user language should be detected
  95. order: ['localStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
  96. // keys or params to lookup language from
  97. lookupLocalStorage: 'lang',
  98. lookupFromPathIndex: 0,
  99. lookupFromSubdomainIndex: 0,
  100. // cache user language on
  101. caches: ['localStorage', 'cookie'],
  102. excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)
  103. // optional expire and domain for set cookie
  104. cookieMinutes: 10,
  105. cookieDomain: 'myDomain',
  106. // optional htmlTag with lang attribute, the default is:
  107. htmlTag: document.documentElement,
  108. // only detect languages that are in the whitelist
  109. checkWhitelist: true,
  110. },
  111. });
  112. export default i18n;