# vve-i18n-cli

> generate an internationalized text resource file

Latest version **9.3.4** (published 2025-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install vve-i18n-cli
pnpm add vve-i18n-cli
yarn add vve-i18n-cli
bun add vve-i18n-cli
```

Provides the commands `vve-i18n-cli`, `vve-i18n-zh-wrap-cli`, `vve-i18n-zh-check-cli`, `vve-i18n-zh-extract-cli`, `vve-i18n-trans-restore-cli`, `vve-i18n-zh-find-untrans-cli`.

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 9.3.4 |
| Published | 2025-08-15 |
| First published | 2019-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 191.7 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 25 |
| Author | nianqin |
| Maintainers | nianqin |
| Keywords | vve, i18n, cli |

## Links

- npm: https://www.npmjs.com/package/vve-i18n-cli
- Repository: https://github.com/vue-viewer-editor/vve-i18n-cli
- Homepage: https://github.com/vue-viewer-editor/vve-i18n-cli#readme
- Issues: https://github.com/vue-viewer-editor/vve-i18n-cli/issues
- npm.io page: https://npm.io/package/vve-i18n-cli

## Dependencies (9)

- [xlsx](https://npm.io/package/xlsx.md) ^0.18.5
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [jsonfile](https://npm.io/package/jsonfile.md) ^5.0.0
- [vinyl-fs](https://npm.io/package/vinyl-fs.md) ^3.0.3
- [commander](https://npm.io/package/commander.md) ^3.0.2
- [map-stream](https://npm.io/package/map-stream.md) 0.0.7
- [lodash.uniq](https://npm.io/package/lodash.uniq.md) ^4.5.0
- [objects-to-csv](https://npm.io/package/objects-to-csv.md) ^1.3.6
- [vve-baidu-translate-service](https://npm.io/package/vve-baidu-translate-service.md) ^3.1.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 9.3.4 (latest) — 2025-08-15
- 9.3.3 — 2025-08-15
- 9.3.2 — 2025-07-14
- 9.3.1 — 2025-07-04
- 9.2.1 — 2025-07-03
- 9.1.1 — 2025-07-02
- 9.0.1 — 2025-07-01
- 8.1.2 — 2025-03-19
- 8.1.1 — 2025-02-11
- 8.0.4 — 2025-02-10
- 7.2.2 — 2024-07-03
- 7.2.1 — 2024-07-03
- 7.1.1 — 2024-03-28
- 7.0.1 — 2024-02-07
- 6.0.4 — 2023-12-25
- … 22 more at https://npm.io/package/vve-i18n-cli/versions

## README

# vve-i18n-cli

[![Build Status](https://travis-ci.org/vue-viewer-editor/vve-i18n-cli.svg?branch=master)](https://travis-ci.org/vue-viewer-editor/vve-i18n-cli)

抽取国际化文本，生成国际化资源文件，配合[vve-i18n-zh-check-cli](README-zh-check.md)和[vve-i18n-zh-wrap-cli](README-zh-wrap.md)可以把中文包裹一层国际化函数，应用无缝变成国际化应用

## 安装

使用npm安装：

```
$ npm install vve-i18n-cli
```

## 使用

在package.json添加

```json
"scripts": {
  "i18n": "vve-i18n-cli"
}
```

然后 `npm run i18n`

## 参数

### 命令行指定参数

```javascript

program
  .version(require('../package.json').version)
  .option("--cwd <path>", "工作目录")
  .option("--root-dir <path>", "国际文本所在的根目录")
  .option(
    "--module-index-rules <items>",
    "模块入口列表",
    commaSeparatedList
  )
  .option(
    "--ignore-module-index-rules <items>",
    "忽略的模块入口列表",
    commaSeparatedList
  )
  .option(
    "--i18n-file-rules <items>",
    "匹配含有国际化文本的文件规则",
    commaSeparatedList
  )
  .option(
    "--ignore-i18n-file-rules <items>",
    "不匹配含有国际化文本的文件规则",
    commaSeparatedList
  )
  .option(
    "--ignore-i18n-file-rules-base-root-dir <items>",
    "不匹配含有国际化文本的文件规则，基于rootDir",
    commaSeparatedList
  )
  .option(
    "--i18n-text-rules <items>",
    "国际化文本的正则表达式，正则中第一个捕获对象当做国际化文本",
    commaSeparatedList
  )
  .option(
    "--keep-key-rules <items>",
    "模块的国际化的json文件需要被保留下的key，即使这些组件在项目中没有被引用",
    commaSeparatedList
  )
  .option(
    "--ignore-key-rules <items>",
    "忽略国际化KEY的规则，这些KEY不会生成再国际化文件中",
    commaSeparatedList
  )
  .option(
    "--keep-origin",
    "默认会删除未引用的key，设置true，原来的key都会被保留下来"
  )
  .option("--out-dir <path>", "生成的国际化资源包的输出目录")
  .option(
    "-l, --i18n-languages <items>",
    "需要生成的国际化语言文件，目前支持zh、en多个用逗号分割，默认全部",
    commaSeparatedList
  )
  .option(
    "--config <path>",
    "配置文件的路径，没有配置，默认路径是在${cwd}/vve-i18n-cli.config.js"
  )
  .option("--disable-config-file", "是否取配置文件")
  .option("-t, --translate", "是否翻译，只翻译每次执行提取到新的key，且满足translateValueRules规则")
  .option("--translate-from-lang", "翻译的基础语言，默认是用中文翻译")
  .option(
    "--force-translate",
    "是否强制翻译，将遍历所有的key，且需满足translateValueRules规则"
  )
  .option("--translate-language <items>", "翻译的语言", commaSeparatedList)
  .option(
    "--translate-use-pin-yin",
    "非中文使用拼音来来翻译"
  )
  .option("--translate-baidu-appid <item>", "Baidu翻译appId")
  .option("--translate-baidu-key <item>", "Baidu翻译key")
  .option(
    "--translate-use-extra-source",
    "使用额外的翻译源"
  )
  .option(
    "--translate-value-rules <items>",
    "需要翻译的Value的规则，只有value满足此条件才会翻译，如果配置空数组，则表示全部都需要翻译",
    commaSeparatedList
  )
  .option(
    "--translate-ignore-key-rules <items>",
    "忽略翻译KEY的规则，规则可以是一个字符串，正则，或者是函数",
    commaSeparatedList
  )
  .option("--copy-index", "模块下${outDir}/index.js文件不存在才拷贝index.js")
  .option("--force-copy-index", "是否强制拷贝最新index.js")
  .parse(process.argv);
```

### 配置文件指定参数

默认配置文件在${cwd}/vve-i18n-cli.config.js，样例内容如下所示

```javascript
module.exports = {
  outDir: 'lang'
}
```

或

```javascript
export default {
  outDir: 'lang'
}
```

### 默认值

```javascript
const config = {
  // 工作目录
  cwd: ".",
  // 根目录，国际文本所在的根目录
  rootDir: "src",
  // 默认所有模块，如果有传module参数，就只处理某个模块
  // '**/module-**/**/index.js'
  moduleIndexRules: ["."],
  // 忽略模块
  ignoreModuleIndexRules: [],
  // 匹配含有国际化文本的文件规则
  i18nFileRules: ["**/*.+(vue|js)"],
  // 不匹配含有国际化文本的文件规则，基于模块的路径
  ignoreI18nFileRules: [],
  // 不匹配含有国际化文本的文件规则，基于rootDir
  ignoreI18nFileRulesBaseRootDir: [],
  // 国际化文本的正则表达式，正则中第一个捕获对象当做国际化文本
  i18nTextRules: [/(?:[\$.])t\([\s\n]*['"](.+?)['"]/g],
  // 模块的国际化的json文件需要被保留下的key，即使这些组件在项目中没有被引用
  // 规则可以是一个字符串，正则，或者是函数
  keepKeyRules: [
    /^G\/+/ // G/开头的会被保留
  ],
  // 规则可以是一个字符串，正则，或者是函数
  ignoreKeyRules: [
  ],
  // 默认会删除未引用的key，设置true，原来的key都会被保留下来
  keepOrigin: false,
  // 生成的国际化资源包的输出目录
  outDir: "lang",
  // 生成的国际化的语言
  i18nLanguages: [
    "zh", // 中文
    "en" // 英文
  ],
  // 忽略特定语言国际化的key, 他的格式 { zh: { ignore: true, keepKeyRules: [] } }
  // 根据设置的语言，ignore: true 表示忽略这个语言的所有 值与key相同 的key，不生成在国际化资源文件中，keepKeyRules表示强制保留某些key
  // 因为一般是中文做key，生成的value也是中文，一般这种情况下，key和value是一样的，会增加体积，是用此参数可以减少这种key的生成在资源文件中，减少体积。
  ignoreKeyValueSameKeys: {},
  // 配置文件的路径，没有配置，默认路径是在${cwd}/vve-i18n-cli.config.js
  config: undefined,
  // 是否取配置文件
  disableConfigFile: false,
  // 是否翻译，只翻译每次执行提取到新的key，且满足translateValueRules规则
  translate: false,
  // 翻译的基础语言，默认是用中文翻译
  translateFromLang: "zh",
  // 是否强制翻译，将遍历所有的key，且需满足translateValueRules规则
  forceTranslate: false,
  // 翻译的语言
  translateLanguage: ["zh", "en"],
  // 非中文使用拼音来来翻译
  translateUsePinYin: false,
  // Baidu翻译appId
  translateBaiduAppid: '',
  // Baidu翻译key
  translateBaiduKey: '',
  // 额外的翻译源 key en
  translateExtraSource: {}, // { en: [{ type: 'file', path: '' }, { type: 'json', data: {} }] },
  // 使用额外的翻译源
  translateUseExtraSource: false,
  // 需要翻译的Value的规则，只有value满足此条件才会翻译，如果配置空数组，则表示全部都需要翻译
  translateValueRules: [
    /[^\x00-\xff]+/ // 中文
  ],
  // 忽略翻译KEY的规则，规则可以是一个字符串，正则，或者是函数
  translateIgnoreKeyRules: [],
  // 模块下${outDir}/index.js文件不存在才拷贝index.js
  copyIndex: false,
  // 是否强制拷贝最新index.js
  forceCopyIndex: false
};
```


### 开发

- node >= 8

```
npm i // 安装依赖
npm test // 测试
npm run release // 发布
git push --follow-tags origin master && npm publish // npm 发布
```

## 捐赠

如果你觉得它有用，你可以给我买一杯奶茶。

<img width="650" src="https://raw.githubusercontent.com/vue-viewer-editor/vve-i18n-cli/master/qrcode-donation.png" alt="donation">

---
_Source: https://npm.io/package/vve-i18n-cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
