Skip to content

Perlmint/ya-i18next-webpack-plugin

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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)"
	],
}