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:

uvx --with llm-anthropic --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
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.1.tar.gz (4.0 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.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for trn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b5f1afb9ac2007fa5a55ae9efcf426f9009c8d720b325a1a5f3e82810bb09311
MD5 bb6de224530cc790421d285c56afcf90
BLAKE2b-256 ed7556cf2aa7b26e8532132382f1e37507c367eba6bd7c093a553ca72305315a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for trn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7540bb0300c03b19cdece8fc67c07f017555415c4b6f4d026f6745f29e7d3452
MD5 51139bb552288e4c67206dd7a2b82f34
BLAKE2b-256 8ff49ee6c601a6af9fbcdf819637936805d1a114fbf5ef5638a29457c36cf4b9

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