我的问题是:
我使用lodash模板在Backbone上编写了一个SPA(webpack在'templates'文件夹中使用它)。我尝试使用i18n-webpack-plugin。 我的lodash模板中有按钮,我想在其上翻译文本。但我不知道如何,因为<%= __(“Permissions”){%>在这里不起作用(仅在.tpl文件中,在.js中可行)。
我的webpack.config.js是:
var webpack = require('webpack'),
I18nPlugin = require("i18n-webpack-plugin"),
languages = {
"en": null,
"de": require("./resources/lang/de/interface.json"),
"es": require("./resources/lang/es/interface.json")
};
module.exports = Object.keys(languages).map(function(language) {
return {
name: language,
entry: {
acl: "./resources/views/js/acl/init"
},
output: {
path: __dirname + "/public/profile/static/js/dist/",
filename: language + ".[name].js"
},
resolve: {
alias: {
"backbone": __dirname + "/resources/views/js/lib/backbone/backbone",
"jquery": __dirname + "/resources/views/js/lib/jquery/dist/jquery",
"lodash": __dirname + "/resources/views/js/lib/lodash/lodash",
"underscore": __dirname + "/resources/views/js/lib/lodash/lodash",
"models": __dirname + "/resources/views/js/acl/models/",
"collections": __dirname + "/resources/views/js/acl/collections/",
"views": __dirname + "/resources/views/js/acl/views/",
"routers": __dirname + "/resources/views/js/acl/routers/",
"templates": __dirname + "/resources/views/templates/",
}
},
devtool: "source-map",
module: {
loaders: [{
test: /\.tpl$/,
loader: "text",
}]
},
plugins: [
new webpack.NoErrorsPlugin(),
new I18nPlugin(
languages[language]
),
],
}
});
这是我的“模板”:__ dirname +“/ resources / views / templates /”示例:
<h1 class="s-h4"><%= __("Permissions") { %></h1>
这是我的./resources/lang/es/interface.json
{
"Permissions": "Permisos"
}
在webpack工作结果文件(es.acl.js)后,我看到&lt;%= __(“权限”){%&gt;,但我想看Permisos