Skip to main content

CLI tool to translate text with LLMs

Project description

trn: CLI tool for translating text using LLMs

Features

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

Installation

With uv installed, you may skip the installation: uvx trn will always run the latest version of command. You can also install it the usual way:

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 into French
trn -t french Hello world

# Translate from stdin
echo "Hello world" | trn

# Translate a file
trn document.pdf

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

# Use custom LLM
trn -m gpt-4o-mini

Configuration

Set environment variables for convenience:

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

Options

> trn --help
usage: trn [-h] -t TO_LANGUAGE [-m MODEL] [-p PROMPT] [-a PROMPT_ADD] [-v] [-d]
           [text ...]

positional arguments:
  text                  Text to translate, or URL, or path to file (default:
                        None)

options:
  -h, --help            show this help message and exit
  -t, --to-language TO_LANGUAGE
                        Target language for translation [env var:
                        TRN_TO_LANGUAGE] (default: None)
  -m, --model MODEL     LLM to use (run 'uvx llm models' for available models)
                        [env var: TRN_MODEL] (default: gemini-2.5-flash)
  -p, --prompt PROMPT   Custom prompt for translation [env var: TRN_PROMPT]
                        (default: Translate the text (it can be in any language)
                        into {to_language}. Don't explaint that the output is a
                        translation. Tell me in case if you don't know about
                        '{to_language}' language. If there is a file attached,
                        translate the contents of the file. {prompt_add})
  -a, --prompt-add PROMPT_ADD
                        Custom prompt for translation [env var: TRN_PROMPT_ADD]
                        (default: )
  -v, --verbose         Enable verbose output [env var: TRN_VERBOSE] (default:
                        False)
  -d, --debug           Enable debug output [env var: TRN_DEBUG] (default:
                        False)

 In general, command-line values override environment variables which override
defaults.

Requirements

  • Python 3.12+
  • LLM API key configured
  • UV installed (optional, but highly recommended)

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.7.tar.gz (4.7 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.7-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for trn-0.1.7.tar.gz
Algorithm Hash digest
SHA256 abb9689423cbf0b3855cbf664642e372b7ba82c17c0e420b310a1e3c89ce607a
MD5 140b9dda9669ce094e3c2ce3c8cbedfc
BLAKE2b-256 435ded3ef8137f1a27caff7e3b6e9a08d10043efecd0d9411ff2a0a5cf110a8b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for trn-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7e3f27d2f46d85ddd28e17f3dffc3fad2e2b65073ab6aaad0e56f18e936ac10c
MD5 c9c1e90657f49c5af0abd66057b2269f
BLAKE2b-256 1d99c989db7fccee681b84bd0ebbb9d8ab1fa85f2483a327ad08f8b162596abe

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