You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

i18next.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* @flow */
  2. import i18next from 'i18next';
  3. import I18nextXHRBackend from 'i18next-xhr-backend';
  4. import LANGUAGES_RESOURCES from '../../../../lang/languages.json';
  5. import MAIN_RESOURCES from '../../../../lang/main.json';
  6. import languageDetector from './languageDetector';
  7. declare var interfaceConfig: Object;
  8. /**
  9. * The available/supported languages.
  10. *
  11. * XXX The element at index zero is the default language.
  12. *
  13. * @public
  14. * @type {Array<string>}
  15. */
  16. export const LANGUAGES = Object.keys(LANGUAGES_RESOURCES);
  17. /**
  18. * The default language.
  19. *
  20. * XXX The element at index zero of {@link LANGUAGES} is the default language.
  21. *
  22. * @public
  23. * @type {string} The default language.
  24. */
  25. export const DEFAULT_LANGUAGE = LANGUAGES[0];
  26. /**
  27. * The options to initialize i18next with.
  28. *
  29. * @type {Object}
  30. */
  31. const options = {
  32. app:
  33. (typeof interfaceConfig !== 'undefined' && interfaceConfig.APP_NAME)
  34. || 'Jitsi Meet',
  35. compatibilityAPI: 'v1',
  36. compatibilityJSON: 'v1',
  37. fallbackLng: DEFAULT_LANGUAGE,
  38. fallbackOnEmpty: true,
  39. fallbackOnNull: true,
  40. // XXX i18next modifies the array lngWhitelist so make sure to clone
  41. // LANGUAGES.
  42. lngWhitelist: LANGUAGES.slice(),
  43. load: 'unspecific',
  44. ns: {
  45. defaultNs: 'main',
  46. namespaces: [ 'main', 'languages' ]
  47. },
  48. resGetPath: 'lang/__ns__-__lng__.json',
  49. useDataAttrOptions: true
  50. };
  51. i18next
  52. .use(I18nextXHRBackend)
  53. .use(languageDetector)
  54. .use({
  55. name: 'resolveAppName',
  56. process: (res, key) => i18next.t(key, { app: options.app }),
  57. type: 'postProcessor'
  58. })
  59. .init(options);
  60. // Add default language which is preloaded from the source code.
  61. i18next.addResourceBundle(
  62. DEFAULT_LANGUAGE,
  63. 'main',
  64. MAIN_RESOURCES,
  65. /* deep */ true,
  66. /* overwrite */ true);
  67. i18next.addResourceBundle(
  68. DEFAULT_LANGUAGE,
  69. 'languages',
  70. LANGUAGES_RESOURCES,
  71. /* deep */ true,
  72. /* overwrite */ true);
  73. export default i18next;