Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

i18next.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. compatibilityAPI: 'v1',
  37. compatibilityJSON: 'v1',
  38. fallbackLng: DEFAULT_LANGUAGE,
  39. fallbackOnEmpty: true,
  40. fallbackOnNull: true,
  41. // XXX i18next modifies the array lngWhitelist so make sure to clone
  42. // LANGUAGES.
  43. lngWhitelist: LANGUAGES.slice(),
  44. load: 'unspecific',
  45. ns: {
  46. defaultNs: 'main',
  47. namespaces: [ 'main', 'languages', 'countries' ]
  48. },
  49. resGetPath: 'lang/__ns__-__lng__.json',
  50. useDataAttrOptions: true
  51. };
  52. i18next
  53. .use(navigator.product === 'ReactNative' ? {} : I18nextXHRBackend)
  54. .use(languageDetector)
  55. .use({
  56. name: 'resolveAppName',
  57. process: (res, key) => i18next.t(key, { app: options.app }),
  58. type: 'postProcessor'
  59. })
  60. .init(options);
  61. // Add default language which is preloaded from the source code.
  62. i18next.addResourceBundle(
  63. DEFAULT_LANGUAGE,
  64. 'countries',
  65. COUNTRIES_RESOURCES,
  66. /* deep */ true,
  67. /* overwrite */ true);
  68. i18next.addResourceBundle(
  69. DEFAULT_LANGUAGE,
  70. 'languages',
  71. LANGUAGES_RESOURCES,
  72. /* deep */ true,
  73. /* overwrite */ true);
  74. i18next.addResourceBundle(
  75. DEFAULT_LANGUAGE,
  76. 'main',
  77. MAIN_RESOURCES,
  78. /* deep */ true,
  79. /* overwrite */ true);
  80. // Add builtin languages.
  81. // XXX: Note we are using require here, because we want the side-effects of the
  82. // import, but imports can only be placed at the top, and it would be too early,
  83. // since i18next is not yet initialized at that point.
  84. require('./BuiltinLanguages');
  85. export default i18next;