Skip to main content

CLI tool to translate text with LLM

Project description

trn

A CLI tool for translating text using LLMs.

Features

  • Multiple input sources: command line arguments, stdin, clipboard, URLs, or files
  • Supports LLMs from OpenAI, Anthropic, and Google Gemini
  • Configurable via command line arguments or environment variables

Installation

If you have uv installed, you don't need to install the package—just use uvx trn. You can also install it normally:

uv tool install trn
# or
pip install trn

Usage

First, set the key for your LLM provider. Example for Google Gemini:

uvx --with llm-gemini llm keys set gemini

Second, specify your target language via the TRN_TO_LANGUAGE environment variable or -t argument. The -t argument takes priority when both are set.

Third, provide text to translate in one of these ways:

  • command line arguments
  • standard input
  • clipboard

The tool checks for arguments first, then standard input, then the clipboard.

You can also translate web pages or local PDF/image files by providing a URL or file path.

Basic Usage

# Translate from clipboard to default language
trn

# Translate command line text
trn -t french Hello world

# Translate from stdin
echo "Hello world" | trn -t german

# Translate a file
trn -t italian document.txt

# Translate from URL
trn -t japanese https://example.com/article

Configuration

Set environment variables for convenience:

export TRN_TO_LANGUAGE=spanish
# optionally:
export TRN_MODEL=gpt-4o-mini

Options

  • -t, --to-language: Target language (required)
  • -m, --model: LLM model to use (default: gpt-4o-mini)
  • --prompt: Custom translation prompt
  • -v, --verbose: Enable verbose output
  • -d, --debug: Enable debug output

Advanced Examples

# Use different model
trn -t spanish -m claude-3-haiku "Good morning"

# Custom prompt
trn -t french --prompt "Translate to formal French" "How are you?"

# Translate web article
trn -t german https://news.example.com/article

Requirements

  • Python 3.12+
  • LLM API keys configured

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trn-0.1.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trn-0.1.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file trn-0.1.2.tar.gz.

File metadata

  • Download URL: trn-0.1.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for trn-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8a60a6df4847fa4d76afd67ed17cb419e6c00d2b766d5ef6f57a3f0bcf4c111a
MD5 d5192ffd3ff625ca826ea0b00ee9da0e
BLAKE2b-256 393def471d16e75bd33575d568a17cd1ef7edcedd998f89f9955ff02ff9fec5e

See more details on using hashes here.

File details

Details for the file trn-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: trn-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for trn-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 44218f1978a41b335e8590993efbfc9707db6e599ea8d94bf790187ea7eeeea3
MD5 bcae413c48dd591d637555c9bf888096
BLAKE2b-256 8c78f5b68bbc422721e08b5a6aaf89cf495be535d3c0da14f158ba20222700c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page