首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

i18n-loader

用法

./colors.json

代码语言:javascript
复制
{
    "red": "red",
    "green": "green",
    "blue": "blue"
}

./de-de.colors.json

代码语言:javascript
复制
{
    "red": "rot",
    "green": "gr?n"
}

call it

代码语言:javascript
复制
// 假如我们的所在区域是“de-de-berlin”
var locale = require("i18n!./colors.json");
// 等待准备就绪,在一个web项目中所有地区只需要一次
// 因为所有区域的语言被合并到一个chunk里
locale(function() {
    console.log(locale.red); // prints rot
    console.log(locale.blue); // prints blue
});

选项

如果想要一次加载然后可以同步地使用, 你应该告诉 loader 所有要使用的地区。

代码语言:javascript
复制
{
    "i18n": {
        "locales": [
            "de",
            "de-de",
            "fr"
        ],
        // "bundleTogether": false
        // this can disable the bundling of locales
    }
}

可选的调用方法

代码语言:javascript
复制
require("i18n/choose!./file.js"); // 根据地区选择正确的文件
                    // 但是不会合并到对象中

require("i18n/concat!./file.js"); // 拼接所有合适的地区
require("i18n/merge!./file.js");  // 合并到对象中
                    // ./file.js 在编译时会被排除掉
require("i18n!./file.json") == require("i18n/merge!json!./file.json")

如果需要在 node 中使用,不要忘记填补(polyfill)require。 可以参考 webpack 文档。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com