Created
February 17, 2016 17:27
-
-
Save LucaColonnello/2d9c73c48b406c64f238 to your computer and use it in GitHub Desktop.
react-i18next with hot replacement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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