ya-i18next-webpack-plugin
v0.5.0
Published
Yet another i18next webpack plugin
Downloads
528
Readme
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)"
],
}