# i18n-alltranslate

> Generate i18N language files

Latest version **1.2.5** (published 2025-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install i18n-alltranslate
pnpm add i18n-alltranslate
yarn add i18n-alltranslate
bun add i18n-alltranslate
```

## 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 | 1.2.5 |
| Published | 2025-07-16 |
| First published | 2022-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 40.3 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Author | wddzzz |
| Maintainers | wddzzz |
| Keywords | i18n, translate |

## Links

- npm: https://www.npmjs.com/package/i18n-alltranslate
- npm.io page: https://npm.io/package/i18n-alltranslate

## Dependencies (9)

- [md5](https://npm.io/package/md5.md) ^2.3.0
- [axios](https://npm.io/package/axios.md) ^0.19.2
- [chalk](https://npm.io/package/chalk.md) 4.1.2
- [openai](https://npm.io/package/openai.md) ^4.57.3
- [crypto-js](https://npm.io/package/crypto-js.md) ^4.1.1
- [single-line-log](https://npm.io/package/single-line-log.md) ^1.1.2
- [node-global-proxy](https://npm.io/package/node-global-proxy.md) ^1.0.1
- [@alicloud/pop-core](https://npm.io/package/@alicloud/pop-core.md) ^1.7.12
- [@google/generative-ai](https://npm.io/package/@google/generative-ai.md) ^0.24.0

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 1.2.5 (latest) — 2025-07-16
- 1.2.4 — 2025-01-16
- 1.2.3 — 2024-12-09
- 1.2.2 — 2024-09-05
- 1.2.1 — 2024-09-05
- 1.2.0 — 2024-09-05
- 1.1.1 — 2022-11-15
- 1.1.0 — 2022-11-14
- 1.0.4 — 2022-11-12
- 1.0.3 — 2022-10-19
- 1.0.2 — 2022-10-19
- 1.0.1 — 2022-10-19
- 1.0.0 — 2022-10-19

## README

# i18n-alltranslate

## 说明
    重磅更新：支持 OpenAI 翻译！支持自定义 api_key、base_url、model
    支持 JSON 文件格式的语言包内容翻译成指定语种并写入其他语言 JSON 文件
    目前支持 有道云翻译 、阿里翻译、谷歌翻译、OpenAI 翻译
    ps:翻译接口有请求频率限制，若一次翻译不成功，建议多试几次呦，或者更换 ip 绕过限制。

    阿里翻译说明：
    除繁体中文、蒙语、粤语外，其他212种语言，可支持任意两种语言之间互译。
    繁体中文、蒙语、粤语仅支持与中文之间的互译。

## 安装

```bash
npm install --save-dev i18n-alltranslate
// or
yarn add i18n-alltranslate
```

## 调用方法

建立一个 js 文件，写入以下内容

```js
const { i18nI18nLang, i18nI18nTranslate } = require('i18n-alltranslate')
const { YDConfigSet, ALIConfigSet, GConfigSet, openAIConfigSet, setI18nLang, setI18nTranslate } = require('i18n-alltranslate')

/**
 * @description: 将中文 JSON 文件翻译写入其他语言 JSON 文件
 * @param {String} dir/语言文件目录
 * @param {String} zh/中文语言文件路径
 * @param {String} other/其他语言文件路径
 * @param {String} lang/语言种类，默认英文
 * @param {String} type/翻译类型，默认全部翻译 all/翻译全部内容 new/仅翻译新增内容
 * @return {type}
 */
const translate = async (dir, zh, en, fromLang, toLang, type) => {
  // 使用 YDConfigSet 方法传入有道云翻译key，则使用有道云翻译
  // YDConfigSet({ YD_APPKEY: '', YD_KEY: '' })
  // 使用 ALIConfigSet 方法传入阿里翻译key，则使用阿里翻译
  // ALIConfigSet({ accessKeyId: '', accessKeySecret: '' })
  // 使用 GConfigSet 方法传入谷歌翻译key和代理信息，则使用谷歌翻译
  // GConfigSet(G_KEY, { proxy: { host: '127.0.0.1', port: '7890' } })
  // 使用 openAIConfigSet，设置 api_key、base_url、model，使用 支持 OpenAI 的 ai 翻译
  openAIConfigSet({
    OPENAI_API_KEY: '',
    OPENAI_BASE_URL: '',
    OPENAI_MODEL: ''
  })
  await setI18nLang(dir, zh)
  await setI18nTranslate(zh, en, fromLang, toLang, type)
}
translate('demo', 'demo/zh.json', 'demo/en.json', 'zh', 'en', 'all')
```

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