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.4.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.4-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trn-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 ba9e318b8cbd16396784627e2eb83da3e541aaae22109133283a245c13a9bc99
MD5 f75e5da2a5515c7ac66f41adc881e68b
BLAKE2b-256 9c318eb84dc04c21cf987580705fc465216179007a602ed8fc2af05cd7d9f97b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for trn-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 66e5add035ff857386a933d6cde4baf52a75cba8336ce5d811bf4555bc478959
MD5 0739ef66a63e0a30780bb9278e61d9ea
BLAKE2b-256 08dcbaa7f19023a1eafd91281bd807d0ac688492c9dd8fe88eebb52c6978011f

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