0.0.9 • Published 8 months ago

json-ai-translation v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

JSON AI Translation

This package makes it simple to keep a project's translation files up to date using AI. It is ideal for the use case where you do all your language edits in a single locale file, e.g. en, then want OpenAI to automatically translate just the changed or new strings into all the other locales. You can then either check these in, or open a pull request to send these suggestions to human translaters.

Note that for this tool to detect which strings have changed in your main locale file, you should run this before committing that file to git.

Getting Started

Install the package from NPM

npm install -g json-ai-translation

JSON AI Translation

CLI Usage

The package assumes that you keep all your files to be translated in a single folder, with each non-nested sub-folder being named after the locale it represents. E.g.

public/locales/en/common.json
public/locales/de/common.json
public/locales/es/common.json
public/locales/ko/common.json

You must tell the script which locale is the authoritive one from which all other locales are translated. The example below assumes that your OpenAI API key is in the OPENAI_API_KEY environment variable.

json-ai-translation --dir public/locales --main en --openaitoken \"$OPENAI_API_KEY\"

Alternatively, to use Anthropic, assuming your API key is in the ANTHROPIC_API_KEY environment variable

json-ai-translation --dir public/locales --main en --anthropicaitoken \"$ANTHROPIC_API_KEY\"

This will cause all other locale files in the public/locales folder to be updated, using OpenAI/Anthropic to translate from the authoritive locale into all the others.

Only values that have changed in the main locale will be updated, so if you have manually edited values in the locale files previously, those will remain unchanged.

Adding a new locale

To add a new locale, simply create a new folder with that locale code, e.g. Portuguese

public/locales/pt

and run the json-ai-translation command again. All the files in the main locale will be created in the new locale, fully translated by AI.

Building to another folder

If you want to the leave the source files unchanged, set the --dest argument to the path to another folder, e.g.

json-ai-translation --dir public/locales --dest build/locales --main en --openaitoken \"$OPENAI_API_KEY\"

Parameters

ParameterDescriptionType
--dirThe folder in which the locale files are storedStringRequired
--mainThe primary locale code, e.g. --main enStringRequired
--openaitokenYour OpenAI token, required unless an Anthropic token is providedStringRequired?
--anthropicaitokenYour AnthropicAI token, required unless an OpenAI token is providedStringRequired?
--destThe folder in which the translated locale files written. Defaults to the same as --dirStringOptional
--aimodelOverride the default AI model for either OpenAI or AnthropicStringOptional
--notranslateA list of strings that should not be translated. For example, product names. E.g. --notranslate "My Cool App" "My Company Name"BooleanOptional
--quietDo not log anything to the console when runningBooleanOptional
--forceForce the translation of all strings in the main locale files, even if they have not changed. This will be slower and more expensiveBooleanOptional

License

MIT

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago