Guest User

Untitled

a guest
Dec 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import * as i18n from 'i18next';
  2. import LanguageDetector from 'i18next-browser-languagedetector';
  3. import * as XHR from 'i18next-xhr-backend';
  4. import Backend from 'i18next-chained-backend';
  5. import LocalStorageBackend from 'i18next-localstorage-backend'; // primary use cache
  6. import { reactI18nextModule } from 'react-i18next';
  7.  
  8. const lang = localStorage.getItem('localesLang');
  9.  
  10. const appIntl: i18n.i18n = i18n.createInstance({
  11. fallbackLng: 'en',
  12. lng: lang,
  13. load: 'languageOnly',
  14. whitelist: ['en', 'ru'],
  15. debug: process.env.NODE_ENV === 'development',
  16. ns: 'common',
  17. defaultNS: 'common',
  18. backend: {
  19. backends: [
  20. LocalStorageBackend, // primary
  21. XHR // fallback
  22. ],
  23. backendOptions: [{
  24. // prefix for stored languages
  25. prefix: 'i18next_res_',
  26.  
  27. // expiration
  28. expirationTime: 7 * 24 * 60 * 60 * 1000,
  29.  
  30. // language versions
  31. versions: {
  32. en: '1.1',
  33. ru: '1.1'
  34. }
  35. }, {
  36. loadPath: '/locales/{{lng}}/{{ns}}.json' // xhr load path for my own fallback
  37. }]
  38. },
  39. interpolation: {
  40. escapeValue: false
  41. },
  42. react: {
  43. wait: true
  44. }
  45. });
  46.  
  47. appIntl
  48. .use(Backend)
  49. // .use(LanguageDetector)
  50. .use(reactI18nextModule)
  51. .init();
  52.  
  53. const t: i18n.TranslationFunction = appIntl.t.bind(appIntl);
  54.  
  55. export { t };
  56.  
  57. export default appIntl;
Add Comment
Please, Sign In to add comment