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

Uploaded Python 3

File details

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

File metadata

  • Download URL: trn-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 6537c70aca43cf1e5e847718afa508563f4a6431528792e90af83aba1b25c19d
MD5 0308087240d367d2beb15d0c5f20dbba
BLAKE2b-256 13a67b78a986073a301a5d284862ef8e13439fd848d31328d1064b96ef8d4838

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trn-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4cf49e20a912198f8a8ecf1f9ce33d43613666023e2b4d49b64aadb8b178955c
MD5 aff56027efea6f4861f56175499f2325
BLAKE2b-256 c9bb0bb6770c89d7c93dd67b08cc475b13523ef2da2d7e1eb06d334759910db8

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