Skip to main content

llm-tr: translate text using llm in your terminal

PyPI Changelog Tests License

llm-tr is a plugin for LLM that lets you translate text directly from your terminal using your favorite large language model. It automatically detects the source language and translates to your preferred language, with smart fallbacks and clipboard integration.

Installation

First, install LLM if you haven't already.

Then install llm-tr:

llm install llm-tr

If you want automatic copying of results to your clipboard, install with the pyclip extra:

llm install 'llm-tr[pyclip]'

Usage

Translate any text from your terminal:

llm tr Hola mundo

Or translate the contents of a file:

llm tr document.txt

The plugin will:

  • Detect the source language of the input (text or file content).
  • Translate to your preferred language (see below for how this is chosen).
  • Print the translation to stdout.
  • If installed with [pyclip], copy the result to your clipboard automatically.

File Translation

When you provide a single argument that is a valid file path, llm-tr will automatically read the file's content and translate it:

# Translate a text file
llm tr readme.txt

# Translate a markdown file
llm tr documentation.md

# Works with any text file
llm tr script.py

If the file cannot be read (doesn't exist, permission issues, or binary file), the argument will be treated as regular text to translate.

Preferred Language Logic

llm-tr determines your target translation language using the following priority:

  1. Explicit Language (CLI or Environment Variable):

    • Use the --language (or -l) option:
      llm tr -l french Hello world
      
    • Or set the LLM_TR_LANGUAGE environment variable:
      export LLM_TR_LANGUAGE=spanish
      
  2. System Language:

    • If no explicit language is set, llm-tr uses your system locale (e.g., LANG environment variable or OS locale settings).
  3. Fallback to English:

    • If neither of the above is available or recognized, English is used as the default target language.

Note: The plugin will never translate into the detected source language. If your preferred language matches the source, it will use the next available option.

Examples

  • Translate to French explicitly:
    llm tr -l french ¡Viva Perón y que la chupen los gorilas!
    
  • Use environment variable for Spanish and quote the input
    export LLM_TR_LANGUAGE=spanish
    llm tr "Proletarier aller Länder, vereinigt euch!"
    
  • Let the system locale decide (e.g., if your system is set to German):
    llm tr Good morning
    
    (If your system language is German, this will translate to German unless the input is already in German.)

Clipboard Integration

If you install llm-tr with [pyclip](https://pypi.org/project/pyclip/` extra (i.e., llm install 'llm-tr[pyclip]'), the translated result will be automatically copied to your clipboard after each translation.

In addition, you can also translate text from your clipboard using the -x (or --paste) option:

llm tr -x

This will read the current clipboard content as the input text to translate, instead of requiring you to type or paste it into the terminal. This is especially useful for quickly translating text you've just copied from another application.

If pyclip is not available or clipboard setup fails, these features are ignored.

System Prompt

llm-tr uses the following system prompt for the LLM:

First, detect the source language of the input text.

You have two preferred languages as target languages: {second_language} and {system_language}. Translate the text into the first preferred language that is different from the detected source language.

Return only the translated text as a string, with no explanations or extra output.

Supported Languages

You can specify your preferred language using either the language name or its code. Supported languages include:

afrikaans (af), arabic (ar), bulgarian (bg), bengali (bn), catalan (ca), czech (cs), danish (da), german (de), greek (el), english (en), spanish (es), estonian (et), persian (fa), finnish (fi), french (fr), hebrew (he), hindi (hi), croatian (hr), hungarian (hu), indonesian (id), italian (it), japanese (ja), korean (ko), lithuanian (lt), latvian (lv), macedonian (mk), malay (ms), norwegian bokmål (nb), dutch (nl), polish (pl), portuguese (pt), romanian (ro), russian (ru), slovak (sk), slovenian (sl), serbian (sr), swedish (sv), thai (th), turkish (tr), ukrainian (uk), vietnamese (vi), chinese (zh).

Metadata

Release files for llm-tr 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-tr 0.2.1
File Size Uploaded Provenance
llm_tr-0.2.1.tar.gz 4.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-tr 0.2.1
File Interpreter ABI Platform
llm_tr-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / llm_tr-0.2.1.tar.gz

Download URL llm_tr-0.2.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
625911de2c42c0c90dec1324456014a338b318c5d065b95977d9f54cdcc6119d
BLAKE2b-256 checksum
How to use checksums
4be35e9774eef7c3923774e9f8637ce4f08abf19dc491bdeaeb5ec2fbf214334
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2025.

Transparency log

Release files / llm_tr-0.2.1-py3-none-any.whl

Download URL llm_tr-0.2.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcf5ca68f39ca6c868a72de63cac2644bbd98ba510ec99bf5d8b68f55faf961f
BLAKE2b-256 checksum
How to use checksums
7118917e69af7f7411e2d4da50398f6d639eb21780f6e47ff0687cc429b98b4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2025.

Transparency log

Security for llm-tr 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for llm_tr-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page