ai-translator.js
A utility that translates JSON or CSV files using OpenAI's API.
Usage
npx @axeptio/ai-translator "./to/translate/*.json" "./translated/{filename}_{locale}.json"
Arguments and options
Arguments:
input Input file or directory
output Output file or directory
Options:
-f, --format <format> Format (csv, json) (default: null)
-l, --locales <locales> Locales to translate to (default: null)
-s, --separator <separator> Separator for CSV files (default: "auto")
-e, --encoding <encoding> Encoding for CSV files (default: "utf8")
-k, --apiKey <apiKey> OpenAI API key
-v, --verbose Verbose mode (default: false)
-j, --jobDescription <jobDescription> Job description file (default: null)
-h, --help display help for command
Interactively
When using the CLI interactively, you will be prompted for the following information:
- Translation context: write in plain english context information to guide the AI (e.g. "This is marketing material for a landing page")
- Writing style: give precise guidelines for the AI to work with.
- Output locales: a list of locales you want to translate to
- Protected fields: a list of fields that should not be translated (e.g. "name", "icon", "slug", etc.)
- Field descriptions: a list of fields that require specific instructions (e.g. "
title
should not exceed 90 characters", etc.)
When using the CLI interactively, you will be asked if you want to save these presets as a job description. If you do, you will be prompted for a name for the job options and a destination folder.
Job Options
If you are processing the same file multiple times, you can save the job options in a JSON file and use it as a template for future runs. The job options file should respect the JSON schema in the src
directory, and look like this:
{
"format": "json",
"context": "This is marketing material for a landing page",
"style": "Formal",
"locales": ["fr", "de", "es"],
"protectedFields": ["name", "icon", "slug"]
}