Skip to content

Instantly share code, notes, and snippets.

@LucaColonnello
Created February 17, 2016 17:27
Show Gist options
  • Save LucaColonnello/2d9c73c48b406c64f238 to your computer and use it in GitHub Desktop.
Save LucaColonnello/2d9c73c48b406c64f238 to your computer and use it in GitHub Desktop.
react-i18next with hot replacement
import i18next from 'i18next'
const resources = require("i18next-resource-store-loader!../assets/i18n/index.js");
i18next
.init({
lng: 'en', // set dynamically on build
fallbackLng: 'en',
resources: resources,
debug: true,
interpolation: {
escapeValue: false // not needed for react!!
}
});
if (module.hot) {
module.hot.accept("i18next-resource-store-loader!../assets/i18n/index.js", () => {
const res = require("i18next-resource-store-loader!../assets/i18n/index.js");
Object
.keys(res)
.forEach((lang) => {
Object
.keys(res[lang])
.forEach((namespace) => {
i18next.addResourceBundle(lang, namespace, res[lang][namespace], true, true );
})
;
})
;
i18next.emit('loaded');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment