i18next-webpack-backend
v0.1.1
Published
Backend JSON loader for webpack applications.
Downloads
72
Readme
i18next-webpack-backend
Backend JSON loader for webpack applications.
Get started
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;
Translation file structures
Folder structure
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
License
Released under the MIT license.