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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // @flow
  2. import COUNTRIES_RESOURCES from 'i18n-iso-countries/langs/en.json';
  3. import i18next from 'i18next';
  4. import I18nextXHRBackend from 'i18next-xhr-backend';
  5. import LANGUAGES_RESOURCES from '../../../../lang/languages.json';
  6. import MAIN_RESOURCES from '../../../../lang/main.json';
  7. import languageDetector from './languageDetector';
  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: Array<string> = 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. backend: {
  33. loadPath: 'lang/{{ns}}-{{lng}}.json'
  34. },
  35. defaultNS: 'main',
  36. fallbackLng: DEFAULT_LANGUAGE,
  37. interpolation: {
  38. escapeValue: false // not needed for react as it escapes by default
  39. },
  40. load: 'languageOnly',
  41. ns: [ 'main', 'languages', 'countries' ],
  42. react: {
  43. useSuspense: false
  44. },
  45. returnEmptyString: false,
  46. returnNull: false,
  47. // XXX i18next modifies the array lngWhitelist so make sure to clone
  48. // LANGUAGES.
  49. whitelist: LANGUAGES.slice()
  50. };
  51. i18next
  52. .use(navigator.product === 'ReactNative' ? {} : I18nextXHRBackend)
  53. .use(languageDetector)
  54. .init(options);
  55. // Add default language which is preloaded from the source code.
  56. i18next.addResourceBundle(
  57. DEFAULT_LANGUAGE,
  58. 'countries',
  59. COUNTRIES_RESOURCES,
  60. /* deep */ true,
  61. /* overwrite */ true);
  62. i18next.addResourceBundle(
  63. DEFAULT_LANGUAGE,
  64. 'languages',
  65. LANGUAGES_RESOURCES,
  66. /* deep */ true,
  67. /* overwrite */ true);
  68. i18next.addResourceBundle(
  69. DEFAULT_LANGUAGE,
  70. 'main',
  71. MAIN_RESOURCES,
  72. /* deep */ true,
  73. /* overwrite */ true);
  74. // Add builtin languages.
  75. // XXX: Note we are using require here, because we want the side-effects of the
  76. // import, but imports can only be placed at the top, and it would be too early,
  77. // since i18next is not yet initialized at that point.
  78. require('./BuiltinLanguages');
  79. export default i18next;