您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

i18next.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // @flow
  2. import i18next from 'i18next';
  3. import I18nextXHRBackend from 'i18next-xhr-backend';
  4. import COUNTRIES_RESOURCES from 'i18n-iso-countries/langs/en.json';
  5. import LANGUAGES_RESOURCES from '../../../../lang/languages.json';
  6. import MAIN_RESOURCES from '../../../../lang/main.json';
  7. import languageDetector from './languageDetector';
  8. declare var interfaceConfig: Object;
  9. /**
  10. * The available/supported languages.
  11. *
  12. * XXX The element at index zero is the default language.
  13. *
  14. * @public
  15. * @type {Array<string>}
  16. */
  17. export const LANGUAGES: Array<string> = Object.keys(LANGUAGES_RESOURCES);
  18. /**
  19. * The default language.
  20. *
  21. * XXX The element at index zero of {@link LANGUAGES} is the default language.
  22. *
  23. * @public
  24. * @type {string} The default language.
  25. */
  26. export const DEFAULT_LANGUAGE = LANGUAGES[0];
  27. /**
  28. * The options to initialize i18next with.
  29. *
  30. * @type {Object}
  31. */
  32. const options = {
  33. app:
  34. (typeof interfaceConfig !== 'undefined' && interfaceConfig.APP_NAME)
  35. || 'Jitsi Meet',
  36. backend: {
  37. loadPath: 'lang/__ns__-__lng__.json'
  38. },
  39. defaultNS: 'main',
  40. fallbackLng: DEFAULT_LANGUAGE,
  41. interpolation: {
  42. escapeValue: false // not needed for react as it escapes by default
  43. },
  44. load: 'languageOnly',
  45. ns: [ 'main', 'languages', 'countries' ],
  46. react: {
  47. useSuspense: false
  48. },
  49. returnEmptyString: false,
  50. returnNull: false,
  51. // XXX i18next modifies the array lngWhitelist so make sure to clone
  52. // LANGUAGES.
  53. whitelist: LANGUAGES.slice()
  54. };
  55. i18next
  56. .use(navigator.product === 'ReactNative' ? {} : I18nextXHRBackend)
  57. .use(languageDetector)
  58. .use({
  59. name: 'resolveAppName',
  60. process: (res, key) => i18next.t(key, { app: options.app }),
  61. type: 'postProcessor'
  62. })
  63. .init(options);
  64. // Add default language which is preloaded from the source code.
  65. i18next.addResourceBundle(
  66. DEFAULT_LANGUAGE,
  67. 'countries',
  68. COUNTRIES_RESOURCES,
  69. /* deep */ true,
  70. /* overwrite */ true);
  71. i18next.addResourceBundle(
  72. DEFAULT_LANGUAGE,
  73. 'languages',
  74. LANGUAGES_RESOURCES,
  75. /* deep */ true,
  76. /* overwrite */ true);
  77. i18next.addResourceBundle(
  78. DEFAULT_LANGUAGE,
  79. 'main',
  80. MAIN_RESOURCES,
  81. /* deep */ true,
  82. /* overwrite */ true);
  83. // Add builtin languages.
  84. // XXX: Note we are using require here, because we want the side-effects of the
  85. // import, but imports can only be placed at the top, and it would be too early,
  86. // since i18next is not yet initialized at that point.
  87. require('./BuiltinLanguages');
  88. export default i18next;