2.0.3 • Published 5 years ago
@zainulbr/i18n-webpack-plugin v2.0.3
npm
npm i -D @zainulbr/i18n-webpack-pluginyarn
yarn add -D @zainulbr/i18n-webpack-pluginThis plugin creates bundles with translations baked in. So you can serve the translated bundle to your clients. Example:
console.log(__("Hello World"));
console.log(__("Missing Text"));var path = require("path");
var I18nPlugin = require("@zainulbr/i18n-webpack-plugin");
var languages = {
"en": null,
"de": require("./de.json")
};
module.exports = Object.keys(languages).map(function(language) {
return {
name: language,
// mode: "development || "production",
entry: "./example",
output: {
path: path.join(__dirname, "dist"),
filename: language + ".output.js"
},
plugins: [
new I18nPlugin(
languages[language]
)
]
};
});{
"Hello World": "Hallo Welt"
}current example. original example from un maintenance repo
plugins: [
...
new I18nPlugin(languageConfig, optionsObj)
],optionsObj.functionName: the default value is__, you can change it to other function name.optionsObj.failOnMissing: the default value isfalse, which will show a warning message, if the mapping text cannot be found. If set totrue, the message will be an error message.optionsObj.hideMessage: the default value isfalse, which will show the warning/error message. If set totrue, the message will be hidden.optionsObj.nested: the default value isfalse. If set totrue, the keys inlanguageConfigcan be nested. This option is interpreted only iflanguageConfigisn't a function.