Skip to main content
Home
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
47%
Published
8 months ago (1.0.0)

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

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@brumor/translatron

Import symbol

import * as translatron from "@brumor/translatron";
or

Import directly with a jsr specifier

import * as translatron from "jsr:@brumor/translatron";

Add Package

pnpm i jsr:@brumor/translatron
or (using pnpm 10.8 or older)
pnpm dlx jsr add @brumor/translatron

Import symbol

import * as translatron from "@brumor/translatron";

Add Package

yarn add jsr:@brumor/translatron
or (using Yarn 4.8 or older)
yarn dlx jsr add @brumor/translatron

Import symbol

import * as translatron from "@brumor/translatron";

Add Package

vlt install jsr:@brumor/translatron

Import symbol

import * as translatron from "@brumor/translatron";

Add Package

npx jsr add @brumor/translatron

Import symbol

import * as translatron from "@brumor/translatron";

Add Package

bunx jsr add @brumor/translatron

Import symbol

import * as translatron from "@brumor/translatron";