+
Skip to content

i18n-ai-translate

Actions
Use ChatGPT or Google Gemini to automatically translate your i18n JSON on every PR
v4.1.2
Latest
Star (78)

i18n‑ai‑translate

AI‑powered localization for your i18next‑style JSON files. Automate translating of single files or entire directories with ChatGPT, Gemini, Claude, or local Ollama models -- while keeping accurate translations, formatting consistent, and intact {{variables}}.

For a detailed walkthrough and advanced tips, see ADVANCED_GUIDE.md.


Why use it?

Feature What it means
Multi‑engine Choose OpenAI, Google, Anthropic, or your own Ollama models
Safe translations Dual verification checks accuracy and formatting
Diff‑aware Only re‑translate keys you changed
Everywhere Use as a CLI, GitHub Action, or Node library
Dry‑run Preview updates before touching disk

Quick start

1 · Install

npm i -g i18n-ai-translate    # or yarn add i18n-ai-translate --dev
export OPENAI_API_KEY=•••     # or GEMINI_API_KEY / ANTHROPIC_API_KEY

2 · Translate a file

i18n-ai-translate translate -i i18n/en.json -o fr \
  -e chatgpt -m gpt-4o

Need more languages? Pass multiple codes (-o fr es de) or -A for all 180+.

3 · Translate a folder

i18n-ai-translate translate -i i18n/en -o fr es de \
  -e chatgpt -m gpt-4o

This recursively translates all *.json files in en and writes to i18n/fr, i18n/es, and i18n/de.

4 · Keep PRs up‑to‑date

Add a one‑liner GitHub Action to auto‑translate whenever en.json changes:

- uses: taahamahdi/i18n-ai-translate@master
  with:
    json-file-path: i18n/en.json
    api-key: ${{ secrets.OPENAI_API_KEY }}

CLI cheat‑sheet

# Translate a file or folder
translate   -i <src>      -o <lang…>   [options]

# Re‑translate only edited keys
diff        -b <before>   -a <after>   [options]

# See all flags
--help

Common flags:

Flag Default Description
-e, --engine chatgpt chatgpt · gemini · claude · ollama
-m, --model gpt-4o e.g. gemini‑2.0‑flash‑exp, claude‑3‑5‑sonnet‑latest
-r, --rate-limit-ms engine‑specific Gap between requests
--dry-run false Don’t write files, preview instead

Full flag list: i18n-ai-translate translate --help.


Use as a library

import { translate } from "i18n-ai-translate";

const fr = await translate({
  inputJSON: require("./en.json"),
  inputLanguage: "en",
  outputLanguage: "fr",
  engine: "chatgpt",
  model: "gpt-4o",
  apiKey: process.env.OPENAI_API_KEY,
});

Advanced topics

  • Prompt modes: csv (faster) vs json (maximum fidelity)
  • Custom prompts: swap in your own generation / verification prompts
  • Placeholders: keep {{prefix}} & {{suffix}} exactly as‑is

i18n-ai-translate is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Use ChatGPT or Google Gemini to automatically translate your i18n JSON on every PR
v4.1.2
Latest

i18n-ai-translate is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载