0.9.5 • Published 2 years ago

webpack-i18n-plugin v0.9.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

中文国际化插件,适用于 vue,react

DEMO

安装

npm install webpack-i18n-plugin -D

为了兼容 vue 和 react,需要同时配置 webpack plugins 和 babel plugins

webpack plugins 配置

// webpack.config.js
const i18nPlugin = require("webpack-i18n-plugin");
plugins: [
  ...
  new i18nPlugin(i18nConfig),
  ...
]
// vue.config.js
chainWebpack: (config) => {
  config
    .plugin('i18n')
    .use('webpack-i18n-plugin')
    .tap(() => {
      return [i18nConfig];
    });
}

babel plugins 配置

// .babelrc | babel.config.js

plugins:[
  ...
  "webpack-i18n-plugin/babel"
]

切换语言

确保语言包最先加载到页面中,中文无需引入语言包

// 页面入口 app.js
const en_US = require("./i18n/en_US"); // 对应语言包
window.$i8n.locale(en_US); // $i18n为全局变量
// other code

插件配置项 Object

名称说明类型必选默认值
i18nDir国际化输出目录Stringi18n
makefile是否输出国际化内容国际化内容不发生变化时,可设置为 falseBooleantrue
translation对应语言的翻译内容Object-

示例

const i18nConfig = {
  translation: {
    en_US: [path.resolve(__dirname, "翻译文件.xlsx")], //en_US语言包
    ja_JP:'',
    ...
  },
};

翻译文件格式参考

备注

  1. 编译结果暴露 $i8n $$i8n 全局方法
  2. 编译后,关注build输出日志,直到无待翻译数据
  3. 如果语言包无法更新,清理node_modules/.cache后重新编译

欢迎fork,提交issues.

License

MIT License.

0.9.5

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.8.4

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.8.1

2 years ago