webpack-contrib / i18n-webpack-plugin

[DEPRECATED] Embed localization into your bundle
MIT License
317 stars 74 forks source link

How to use this in jade-loader? #53

Open Teemo12345 opened 7 years ago

Teemo12345 commented 7 years ago
const path = require("path"),
webpack = require("webpack"),
htmlWebpackPlugin = require("html-webpack-plugin");
const i18nWebpackPlugin = require('i18n-webpack-plugin');

function getConfig(lang){
    return {
        entry:{
            index:"./src/app/page/index.js"
        },
        output:{
            path:path.resolve(__dirname+"/dist/"),
            filename:lang+"/js/"+lang+"-[name]-[hash:5].js"
        },
        module:{
            rules:[
                {
                    test:/\.jade$/,
                    loader:"jade-loader",
                    options:{
                        pretty:true,
                        template:{__:__}
                    }               
                },
                {
                    test:/\.json$/,
                    loader:"json-loader"
                }
            ]
        },
        plugins:[
            new webpack.ProvidePlugin({
                $:'jquery'
            }),
            new i18nWebpackPlugin(languages[lang]),
            new htmlWebpackPlugin({
                template:'src/tmpl/index.jade',
                filename:lang+"/index.html"
            })
        ],

    }
}

let languages = {
    "en_US":"/src/config/locales/en.json",
    "zh_CN":"/src/config/locales/zh.json"
}
module.exports=Object.keys(languages).map(function(lang){
    return getConfig(lang)

})

ERROR in Template execution failed: TypeError: __ is not a function

ERROR in   TypeError: __ is not a function
Teemo12345 commented 7 years ago

@jhnns @bebraw use i18n-webpack-plugin on Support jade-loader ?