A command-line tool to translate JSON files using OpenAI.
deno install --global -f -A -n translatron jsr:@brumor/translatron/cli# Set your OpenAI API key
export OPENAI_API_KEY='your-api-key'
# Translate a file
translatron -f input.json -l es -s style-guide.json| Argument | Alias | Required | Description | Default |
|---|---|---|---|---|
| --file | -f | Yes | Path to the JSON file to translate | - |
| --locale | -l | Yes | Target locale (e.g., es, fr, de) | - |
| --style-guide | -s | No | Path to style guide JSON file | - |
| --chunk-size | -c | No | Maximum tokens per translation chunk | 2000 |
Basic translation:
translatron -f input.json -l esWith style guide:
translatron -f input.json -l fr -s style.jsonCustom chunk size:
translatron -f large.json -l de -c 1000import { Translatron } from "jsr:@brumor/translatron";
// With default console.log logger
const translator = new Translatron("your-api-key");
// With custom logger
const customLogger = (message: string) => {
// Add timestamp
console.log(`[${new Date().toISOString()}] ${message}`);
};
const translator = new Translatron("your-api-key", customLogger);
await translator.translateJsonFile("input.json", "es", "style-guide.json");{
"general": "Use formal tone",
"locales": {
"es": "Use 'usted' form",
"fr": "Use 'vous' form"
},
"projectContext": {
"description": "E-commerce website",
"domain": "Retail",
"targetAudience": "General public"
}
}import { Translatron } from "jsr:@brumor/translatron";
const translator = new Translatron("your-api-key");
await translator.translateJsonFile("input.json", "es", "style-guide.json");
// Or use string API
const result = await translator.translateJsonString(
content,
"es",
existingTranslations,
styleGuide
);License MIT