Guest User

Untitled

a guest
Jan 16th, 2019
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import i18n from './src/i18n';
  3. import Backend from 'i18next-sync-fs-backend';
  4. // import XHR from 'i18next-xhr-backend';
  5. import { renderToString } from 'react-dom/server';
  6.  
  7. const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
  8.    i18n
  9.    .use(Backend)
  10.    .init({
  11.       initImmediate: false,
  12.       backend: {
  13.          loadPath: 'https://api.sitename.tld/v1/locale/{{lng}}.json',
  14.       },
  15.    })
  16.    .loadNamespaces(['common'], () => {
  17.       replaceBodyHTMLString(renderToString(bodyComponent))
  18.    })
  19. }
  20.  
  21. export default replaceRenderer;
RAW Paste Data