Backend JSON loader for webpack applications.
Install i18next-webpack-backend
package.
$ npm install i18next-webpack-backend
Add module to your i18n configuration and provide context to load translations from to backend
import i18next from "i18next";
import { WebpackBackend } from "i18next-webpack-backend";
const i18n = i18next.use(WebpackBackend).init({
backend: {
context: require.context("./path/to/translations", true, /\.json$/, "lazy")
}
});
export default i18n;
If you are using multiload adapder:
import i18next from "i18next";
import { WebpackBackend } from "i18next-webpack-backend";
import BackendAdapter from "i18next-multiload-backend-adapter";
const i18n = i18next.use(BackendAdapter).init({
backend: {
backend: WebpackBackend,
backendOption: {
context: require.context("./path/to/translations", true, /\.json$/, "lazy")
}
}
});
export default i18n;
Example translations file structure:
.
└── translations/
├── en/
│ ├── commons.json
│ ├── validation.json
│ ├── glosarry.json
│ └── pages/
│ ├── login.json
│ └── register.json
└── lt/
├── commons.json
├── validation.json
├── glosarry.json
└── pages/
├── login.json
└── register.json
Released under the MIT license.