translate-auto
v1.5.5
Published
i18n 自动翻译
Downloads
717
Readme
translate-auto
安装
npm i -D translate-auto
在根目录可以配置 translate-config.json 文件
{
appKey: "", // 应用key
secretKey: "", // 密钥key
channel: "google", // 翻译渠道,支持custom、google、youdao、baidu,默认google翻译
channelCustomUrl: '', // 自定义渠道翻译
//
targetPath: "src/locales", // 目标地址
languageList: ["zh", "en"], // 语言列表
regexp: `\\$t\\(['"]([^'"]+)['"][,\\)]`, // 提取文字正则,默认提取$t()的第一个参数值
defaultLocale: "zh", // 默认key值语言
defaultRegexp: `[\\u4E00-\\u9FA5]`, // 提取key值正则,获取翻译文本(例如:判断字符串中是否包含至少一个中文字符)
//
filePath: "src", // 需要翻译的目录
fileSuffix: [".vue", ".js", ".jsx", ".ts", ".tsx"], // 指定翻译的文件后缀
excludes: ["node_modules", "dist"], // 排除翻译的目录
}
执行翻译
npm run translate // 全局翻译(在 package.json 文件中的 scripts 对象添加 "translate": "node node_modules/translate-auto")
npm run translate lang=en // 单独翻译某种语言(一般用于新增某种语言,例如新增英文语言)