iuap-design/blog

企业级应用的国际化解决方案(前端部分)

Opened this issue · 1 comments

企业级应用的国际化解决方案

随着业务的对外发展,应用的国际化解决方案提上日程,本文仅限于应用前端开发部分的国际化方案讨论

需求及待解决问题

  • 整站资源的多语言编译:html/js/css/json
  • 数据传输的多语
  • 前端公共框架和插件的多语
  • 上下文context(后端负责)

参考示例

https://github.com/GuoYongfeng/i18n-webpack-demos

技术方案

i18next: internationalization ecosystem

基于i18next的国际化方案:http://i18next.com/docs/

webpack的i18n-webpack-plugin插件

示例代码

var path = require("path");
var I18nPlugin = require("i18n-webpack-plugin");
var languages = {
    "en": null,
    "de": require("./de.json")
};
module.exports = Object.keys(languages).map(function(language) {
    return {
        name: language,
        entry: "./example",
        output: {
            path: path.join(__dirname, "js"),
            filename: language + ".output.js"
        },
        plugins: [
            new I18nPlugin(
                languages[language]
            )
        ]
    };
});

更多信息:

现有需求
1.使用requirejs ,且使用了webpack
2.使用了requirejs,没有使用webpack
3.使用了webpack + es6