Skip to content

Brumor/translatron

Repository files navigation

JSON Translator CLI

A command-line tool to translate JSON files using OpenAI.

Installation

deno install --global -f -A -n translatron jsr:@brumor/translatron/cli

Usage

# 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

CLI Arguments

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

Examples

Basic translation:

translatron -f input.json -l es

With style guide:

translatron -f input.json -l fr -s style.json

Custom chunk size:

translatron -f large.json -l de -c 1000

API Usage

import { 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");

Example Files

Style Guide (style.json)

{
  "general": "Use formal tone",
  "locales": {
    "es": "Use 'usted' form",
    "fr": "Use 'vous' form"
  },
  "projectContext": {
    "description": "E-commerce website",
    "domain": "Retail",
    "targetAudience": "General public"
  }
}

Alternative API Usage

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

About

AI powered CLI translation tool with support for JSON files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •