ya-i18next-webpack-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

npm version Build Status Coverage Status dependencies Status devDependencies Status

ya-i18next-webpack-plugin

Yet another i18next webpack plugin

This plugin collects keys from webpack parsing phase, saves missing translations into specified path, copies translation files.

usage

webpack.config.js

const i18nextPlugin = require("ya-i18next-webpack-plugin").default;

module.exports = {
    plugins: [
        new i18nextPlugin({
            defaultLanguage: "en",
            languages: ["en", "ko"],
            functionName: "_t",
            resourcePath: "./locales/{{lng}}/{{ns}}.json",
            pathToSaveMissing: "./locales/{{lng}}/{{ns}}-missing.json"
        })
    ]
};

index.js

import * as i18next from 'i18next';
import * as Backend from 'i18next-xhr-backend';
import * as i18nConf from "ya-i18next-webpack-plugin/config";

if (window._t === undefined) {
	i18next
		.use(Backend)
		.init({
			fallbackLng: i18nConf.DEFAULT_NAMESPACE,
			whitelist: i18nConf.LANGUAGES,
			backend: {
				loadPath: `${__webpack_public_path__}${i18nConf.RESOURCE_PATH}`
			}
		});
	window._t = i18next.t;
}

console.log(_t("hello_world"));

example missing keys

{
	"hello_world": [
		"index.js(18,16)"
	],
}

Package Sidebar

Install

npm i ya-i18next-webpack-plugin

Weekly Downloads

57

Version

0.5.0

License

MIT

Unpacked Size

39.3 kB

Total Files

7

Last publish

Collaborators

  • perlmint