Gathering detailed insights and metrics for i18n-ai-translate
Gathering detailed insights and metrics for i18n-ai-translate
Gathering detailed insights and metrics for i18n-ai-translate
Gathering detailed insights and metrics for i18n-ai-translate
@lobehub/i18n-cli
Lobe i18n is a CLI tool that automate translate your i18n localization with AI
i18n-ai-trans
i18n-translate 是一个高效、简介的多语言翻译工具,安装后只需简单几步就能实现整个多语言文本的快速翻译。
generaltranslation
A language toolkit for AI developers
@yxw007/translate
A simple library that supports multiple translation engines
Use ChatGPT, Gemini, DeepSeek, Llama, or Claude to translate your i18n JSON to any language
npm install i18n-ai-translate
Typescript
Module System
Node Version
NPM Version
TypeScript (99.9%)
JavaScript (0.1%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
GPL-3.0 License
69 Stars
331 Commits
5 Forks
1 Watchers
3 Branches
3 Contributors
Updated on Jul 18, 2025
Latest Version
4.1.2
Package Id
i18n-ai-translate@4.1.2
Unpacked Size
2.74 MB
Size
805.67 kB
File Count
200
NPM Version
11.4.2
Node Version
24.3.0
Published on
Jul 18, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
19
19
i18n-ai-translate
Leverage ChatGPT, Gemini, Ollama, or Claude for seamless translation of localization files. Supports directories of nested translation files. Requires i18next-style JSON files.
Three prompts are chained to ensure each translation is well-formed.
Translation and verification is done in two separate steps.
History is retained between calls to ensure consistency when translating the entire file.
https://github.com/user-attachments/assets/4909bf01-3e7a-464a-9c6e-2d1b82cc47d0
Incorporate it into your CI with a GitHub Action to auto-translate keys for every pull request as a new commit. All configurable options available in action.yml.
The following translates every PR where i18n/en.json
has been modified:
1name: i18n-ai-translate 2 3on: 4 pull_request: 5 # Only trigger when en.json has been modified 6 paths: 7 - "i18n/en.json" 8 9jobs: 10 build: 11 runs-on: ubuntu-latest 12 steps: 13 - name: i18n-ai-translate 14 uses: taahamahdi/i18n-ai-translate@master 15 with: 16 json-file-path: i18n/en.json 17 api-key: ${{ secrets.OPENAI_API_KEY }}
1git clone git@github.com:taahamahdi/i18n-ai-translate.git 2cd i18n-ai-translate 3yarn 4cp /home/en.json jsons/ 5 6# Generate French translations 7npm run i18n-ai-translate -- translate -i en.json -o fr.json --engine chatgpt --model gpt-4o --api-key <openai_key>
1yarn add i18n-ai-translate 2 3# Generate French translations 4npx i18n-ai-translate translate -i en.json -o fr.json --engine gemini --model gemini-2.0-flash-exp --api-key <gemini_key> 5 6# Or, assuming you already have other translations in the current directory 7npx i18n-ai-translate diff --before en-before.json --after en.json --input-language English --engine claude --model claude-3-5-sonnet-latest --api-key <anthropic_key>
1import { translate } from "i18n-ai-translate"; 2... 3const englishJSON = { 4 "welcomeMessage": "Welcome, {{name}}!", 5 "messages": { 6 "notifications_one": "You have one notification", 7 "notifications_other": "You have {{count}} notifications", 8 "delete": "Would you like to delete the \"{{name}}\" category?" 9 } 10}; 11 12const frenchTranslation = await translate({ 13 inputJSON: englishJSON, 14 inputLanguage: "English", 15 outputLanguage: "French", 16 ... 17}); 18 19console.log(frenchTranslation);
1{ 2 "welcomeMessage": "Bienvenue, {{name}} !", 3 "messages": { 4 "notifications_one": "Vous avez une notification", 5 "notifications_other": "Vous avez {{count}} notifications", 6 "delete": "Voulez-vous supprimer la catégorie « {{name}} » ?" 7 } 8}
Use i18n-ai-translate translate
to convert a local i18n JSON file to any language. Relative paths begin from the jsons/
directory.
Use i18n-ai-translate diff
to find the differences between two versions of a source language file, and apply them to all language files in the same directory.
Create a .env
file with an entry for your API key, or pass the --api-key
flag.
GEMINI_API_KEY=<your Gemini API key>
OPENAI_API_KEY=<your OpenAI API key>
ANTHROPIC_API_KEY=<your Anthropic API key>
For Ollama, create an entry for your host, use the --host
flag to set a custom host and path (Defaults to localhost:11434
).
OLLAMA_HOSTNAME=<the server and port number running Ollama>
Usage: i18n-ai-translate [options] [command]
Use ChatGPT or Gemini to translate your i18n JSON to any language
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
translate [options]
diff [options]
help [command] display help for command
Usage: i18n-ai-translate translate [options]
Options:
-i, --input <input> Source i18n file or path of source language, in the jsons/ directory if a relative path is given
-o, --output-languages [language codes...] A list of languages to translate to
-e, --engine <engine> Engine to use (chatgpt, gemini, ollama, or claude)
-m, --model <model> Model to use (e.g. gpt-4o, gemini-2.0-flash-exp, llama3.3, claude-3-5-sonnet-latest)
-r, --rate-limit-ms <rateLimitMs> How many milliseconds between requests (defaults to 1s for Gemini, 120ms (at 500RPM) for ChatGPT, 1200ms
for Claude)
-f, --force-language-name <language name> Force output language name
-A, --all-languages Translate to all supported languages
-p, --templated-string-prefix <prefix> Prefix for templated strings (default: "{{")
-s, --templated-string-suffix <suffix> Suffix for templated strings (default: "}}")
-k, --api-key <API key> API key
-h, --host <hostIP:port> The host and port number serving Ollama. 11434 is the default port number.
--ensure-changed-translation Each generated translation key must differ from the input (for keys longer than 4) (default: false)
-n, --batch-size <batchSize> How many keys to process at a time (default: "32")
--skip-translation-verification Skip validating the resulting translation through another query (default: false)
--skip-styling-verification Skip validating the resulting translation's formatting through another query (default: false)
--override-prompt <path to JSON file> Use the prompts from the given JSON file, containing keys for at least one of generationPrompt,
translationVerificationPrompt, stylingVerificationPrompt
--prompt-mode <prompt-mode> Chose between 'csv' mode for better performance and 'json' mode for better compatibility,
--batch-max-tokens <batch-max-tokens> For json mode only, maximum size of a single request in tokens
--verbose Print logs about progress (default: false)
--help display help for command
Usage: i18n-ai-translate diff [options]
Options:
-b, --before <fileOrDirectoryBefore> Source i18n file or directory before changes, in the jsons/ directory if a relative path is given
-a, --after <fileOrDirectoryAfter> Source i18n file or directory after changes, in the jsons/ directory if a relative path is given
-l, --input-language <inputLanguageCode> The input language's code, in ISO6391 (e.g. en, fr)
-e, --engine <engine> Engine to use (chatgpt, gemini, ollama, or claude)
-m, --model <model> Model to use (e.g. gpt-4o, gemini-2.0-flash-exp, llama3.3, claude-3-5-sonnet-latest)
-r, --rate-limit-ms <rateLimitMs> How many milliseconds between requests (defaults to 1s for Gemini, 120ms (at 500RPM) for ChatGPT, 1200ms for
Claude)
-k, --api-key <API key> API key
-h, --host <hostIP:port> The host and port number serving Ollama. 11434 is the default port number.
--ensure-changed-translation Each generated translation key must differ from the input (for keys longer than 4) (default: false)
-p, --templated-string-prefix <prefix> Prefix for templated strings (default: "{{")
-s, --templated-string-suffix <suffix> Suffix for templated strings (default: "}}")
-n, --batch-size <batchSize> How many keys to process at a time (default: "32")
--skip-translation-verification Skip validating the resulting translation through another query (default: false)
--skip-styling-verification Skip validating the resulting translation's formatting through another query (default: false)
--override-prompt <path to JSON file> Use the prompts from the given JSON file, containing keys for at least one of generationPrompt,
translationVerificationPrompt, stylingVerificationPrompt
--prompt-mode <prompt-mode> Chose between 'csv' mode for better performance and 'json' mode for better compatibility,
--batch-max-tokens <batch-max-tokens> For json mode only, maximum size of a single request in tokens
--verbose Print logs about progress (default: false)
--help display help for command
npx i18n-ai-translate translate -i en.json -o fr
en.json
file in jsons/
to French, and save the output in fr.json
npx i18n-ai-translate translate -i en.json -o es de nl --engine gemini
en.json
file in jsons/
to Spanish, German, and Dutch, and save each file in jsons/
, using Google Gemininpx i18n-ai-translate diff -b en.json -a en-after.json -l English --verbose --engine ollama --host my-olllama-server.com:12345
en.json
and en-after.json
for all files in the en.json
directory, with logging enabled using Ollama running on my-ollama-server.com:12345
npx i18n-ai-translate translate -i en.json -A --engine chatgpt --model gpt-4-turbo --api-key <my_key> --rate-limit-ms 150 -n 64
en.json
file in jsons/
to 180+ languages, save each file in jsons/
, using the GPT-4 Turbo model of ChatGPT, with the given key, a rate limit of 150ms between requests, and 64 keys sent in each batchnpx i18n-ai-translate diff -b en -a en-after --engine claude
en/
and en-after/
for all JSON files in both directories using Claudenpx i18n-ai-translate translate -i en.json -o fr --engine chatgpt --model gpt-4o --api-key <my_key> --dry-run
en.json
to French would be, but do not actually write the output to disk. A directory is created in /tmp
with the completed translations and patches to apply to existing translations.Alternatively, import this project and use it to convert JSONs on-the-fly with translate()
, or use translateDiff()
to fetch updates to modified keys when your source i18n file has changed.
1import { translate, translateDiff } from "i18n-ai-translate";
2
3...
4
5const translation = await translate({
6 apiKey, // OpenAI/Gemini/Anthropic API key
7 batchMaxTokens, // Maximum amount of tokens for one request
8 batchSize, // How many keys to process at a time
9 chatParams, // Additional configuration to pass to the model
10 engine, // ChatGPT, Gemini, Ollama, or Claude
11 ensureChangedTranslation, // Every key longer than 4 characters must be different than the input
12 host, // The host and port number running Ollama
13 inputJSON, // JSON to translate
14 inputLanguage, // Language of inputJSON
15 model, // Model to use (e.g. gpt-4o, gemini-2.0-flash-exp, llama3.3, claude-3-5-sonnet-latest)
16 outputLanguage, // Targeted language (e.g. French, Spanish, etc.)
17 overridePrompt, // Set custom prompts for generation or verification
18 promptMode, // Chose between 'csv' mode and 'json' mode
19 rateLimitMs, // How many milliseconds between requests
20 skipStylingVerification, // Whether to skip an additional query to see whether the text formatting remained consistent
21 skipTranslationVerification, // Whether to skip an additional query to see whether the resultant translation makes sense
22 templatedStringPrefix, // The start of inline variables; defaults to "{{"
23 templatedStringSuffix, // The end of inline variables; defaults to "}}"
24 verbose, // Print status of conversion to stdout/stderr
25 dryRun, // Whether to write the output to disk
26});
27
28const translations = await translateDiff({
29 apiKey, // OpenAI/Gemini/Anthropic API key
30 batchMaxTokens, // Maximum amount of tokens for one request
31 batchSize, // How many keys to process at a time
32 chatParams, // Additional configuration to pass to the model
33 engine, // ChatGPT, Gemini, Ollama, or Claude
34 ensureChangedTranslation, // Every key longer than 4 characters must be different than the input
35 host, // The host and port number running Ollama
36 inputJSONAfter, // The source translation after a change
37 inputJSONBefore, // The source translation before a change
38 inputLanguage, // Language of inputJSONBefore/After
39 model, // Model to use (e.g. gpt-4o, gemini-2.0-flash-exp, llama3.3, claude-3-5-sonnet-latest)
40 overridePrompt, // Set custom prompts for generation or verification
41 promptMode, // Chose between 'csv' mode and 'json' mode
42 rateLimitMs, // How many milliseconds between requests
43 skipStylingVerification, // Whether to skip an additional query to see whether the text formatting remained consistent
44 skipTranslationVerification, // Whether to skip an additional query to see whether the resultant translation makes sense
45 templatedStringPrefix, // The start of inline variables; defaults to "{{"
46 templatedStringSuffix, // The end of inline variables; defaults to "}}"
47 toUpdateJSONs, // An object of language codes to their translations
48 verbose, // Print status of conversion to stdout/stderr
49 dryRun, // Whether to write the output to disk
50});
Batches of the i18n input are passed in. Each call is checked to ensure no keys are lost, all templated strings are retained, and no translations were skipped.
You are a professional translator.
Translate each line from ${inputLanguage} to ${outputLanguage}.
Return translations in the same text formatting.
Maintain case sensitivity and whitespacing.
Output only the translations.
All lines should start and end with an ASCII quotation mark (").
\`\`\`
${input}
\`\`\`
The output of the translation is sent back to ensure the model is okay with the translation. If this fails, the translation is re-generated.
Given a translation from ${inputLanguage} to ${outputLanguage} in CSV form, reply with NAK if _any_ of the translations are poorly translated.
Otherwise, reply with ACK.
Only reply with ACK/NAK.
\`\`\`
${inputLanguage},${outputLanguage}
${mergedCSV}
\`\`\`
Formatting from the input should be retained where possible. If punctuation, capitalization, or whitespaces differ between the source and the translation, the translation is re-generated.
Given text from ${inputLanguage} to ${outputLanguage} in CSV form, reply with NAK if _any_ of the translations do not match the formatting of the original.
Check for differing capitalization, punctuation, or whitespaces.
Otherwise, reply with ACK.
Only reply with ACK/NAK.
\`\`\`
${inputLanguage},${outputLanguage}
${mergedCSV}
\`\`\`
Batches of the i18n input are passed in. Each call is checked to ensure no keys are lost, all templated strings are retained, and no translations are skipped.
You are a professional translator.
Translate from ${inputLanguage} to ${outputLanguage}.
- Translate each object in the array.
- 'original' is the text to be translated.
- 'translated' must not be empty.
- 'context' is additional info if needed.
- 'failure' explains why the previous translation failed.
- Preserve text formatting, case sensitivity, and whitespace.
Special Instructions:
- Treat anything in the format {{variableName}} as a placeholder. Never translate or modify its content.
- Do not add your own variables
- The number of variables like {{timeLeft}} must be the same in the translated text.
- Do not convert {{NEWLINE}} to \\n.
Return the translation as JSON.
\`\`\`json
${input}
\`\`\`
The output of the translation is sent back to ensure the model is okay with the translation/formatting. If this fails, the translation is re-generated.
You are a professional translator.
Check translations from ${inputLanguage} to ${outputLanguage}.
- Verify each object in the array.
- 'original' is the text to be translated.
- 'translated' is the translated text.
- 'context' is additional info if needed.
- 'failure' explains why the previous translation failed.
- check for Accuracy (meaning, tone, grammar), Formatting (case, whitespace, punctuation).
If correct, return 'valid' as 'true' and leave 'fixedTranslation' and 'issue' empty.
If incorrect, return 'valid' as 'false' and put the fixed translation in 'fixedTranslation' and explain what is 'issue'.
Special Instructions:
- Treat anything in the format {{variableName}} as a placeholder. Never translate or modify its content.
- Do not add your own variables
- The number of variables like {{timeLeft}} must be the same in the translated text.
- Do not convert {{NEWLINE}} to \\n.
Allow minor grammar, phrasing, and formatting differences if meaning is clear.
Flag only significant issues affecting accuracy or readability.
Return the verified as JSON.
\`\`\`json
${input}
\`\`\`
Replace the aforementioned prompts with your own by creating a JSON file containing keys of at least one of generationPrompt
, translationVerificationPrompt
, or stylingVerificationPrompt
(only used in CSV mode). Then, pass it as an argument with --override-prompt <path to file>
. Be sure to include templated arguments like ${inputLanguage}
as part of the prompt.
Add the --dry-run
flag to see what the translation would be without actually writing any files. A directory is created in /tmp
with the completed translations and patches to apply to existing translations.
No vulnerabilities found.
No security vulnerabilities found.