超实用!一个命令搞定 Web 国际化( 三 )

配置详情

超实用!一个命令搞定 Web 国际化

文章插图
 
module.exports = {// cli 语言cliLang: 'zh',// 项目类型:react | vue | jsprojectType: '[react]',// 默认包裹和提取词条的目录srcPath: './',// 扫描文件格式fileExt: 'js,ts,tsx',// 包裹的字符集,下面是中文wrapCharacter: '[u4e00-u9fa5]',// 包裹词条的名字wrapperFuncName: 't',// 忽略掉包裹的方法,多个用,分隔excludeWrapperFuncName: 'console.log,console.error',// jsx中的文字包裹方式,true用<trans></trans>,false用【wrapperFuncName】的value包裹jsx2Trans: false,// 当文件需要翻译时引入的文件importStr: `import {t} from './i18n;';n`,// 排除目录,此目录下的不会不会执行包裹和提取词条操作exclude: 'node_modules,dist,git',// 翻译词条目录localeDir: './locales',// 翻译语种languages: 'zh,en',// 源语言sourceLanguage: 'zh',// 翻译词条文件名transFileName: 'translation',// 翻译词条文件格式: json, potransFileExt: 'json',// 翻译词库目录(自动翻译目录)targetTransDir: './translations',// 翻译词库文件名targetTransFile: 'sourceTranslation.json',// 腾讯云 secretIdsecretId: '',// 腾讯云 secretKeysecretKey: '',};未来规划
  • [ ] 网页多语言显示异常检测
  • [ ] 丰富提取文件(po, csv, Excel 等等)
  • [ ] 增加 git 模式,针对当前改动的文件才转 AST 包裹,提取
  • [ ] 词条提取 cleanMode,目前如果代码中没有这个词条了,提取后的文件依然会有
其他源码https://github.com/wuqiang1985/i18n-helper
NPM 包https://www.npmjs.com/package/i18n-helper-cli
目前还在完善中,欢迎大家试用,大家有问题可以提 issue 。

【超实用!一个命令搞定 Web 国际化】


推荐阅读