0.1.1 • Published 4 years ago

i18next-webpack-backend v0.1.1

Weekly downloads
4,866
License
MIT
Repository
github
Last release
4 years ago

i18next-webpack-backend

Backend JSON loader for webpack applications.

NPM version

Build Status

Dependencies Dev dependencies

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.