购物车
登陆 / 注册
微信扫码登陆

推荐手册

i18n-loader


用法

./colors.json

{
    "red": "red",    
    "green": "green",    
    "blue": "blue"
}

./de-de.colors.json

{
    "red": "rot",    
    "green": "gr�n"
}

调用

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

配置

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

{
  "i18n": {
      "locales": [
            "de",      
            "de-de",      
            "fr"
    ],
        // "bundleTogether": false    
        // 可以禁止所有地区打包到一起
  }
}

可选的调用方法

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 文档。

License

MIT (http://www.opensource.org/licenses/mit-license.php)

网站导航
标签地图
学习路径
视频教程
开发软件
旗下子站
php中文网
phpstudy
技术文章
文档工具
关于我们
企业合作
人才招聘
联系我们
讲师招募
QQ交流群
QQ官方交流群
微信公众号
微信公众号