Skip to main content

Use LLM to translate in your shell

Project description

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

The plugin will:

  • Detect the source language of the input.
  • 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.

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_TRANS_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 Hello world
    
  • Use environment variable for Spanish:
    export LLM_TRANS_LANGUAGE=spanish
    llm tr Bonjour tout le monde
    
  • 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).

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

llm_tr-0.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_tr-0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file llm_tr-0.1.tar.gz.

File metadata

  • Download URL: llm_tr-0.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llm_tr-0.1.tar.gz
Algorithm Hash digest
SHA256 61ef6ba08a7a6bf09d262e1d8cb91c7e15ff963f88669ca7451cc4f0f5e1c798
MD5 1d2adaae9d2fcc9f2ebcb106e1d31574
BLAKE2b-256 7b7782a903d9a16ff3c6910b65f08224a681bfff7c550650aaa693641213f064

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_tr-0.1.tar.gz:

Publisher: cd.yml on mgaitan/llm-tr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_tr-0.1-py3-none-any.whl.

File metadata

  • Download URL: llm_tr-0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llm_tr-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec13b3293b6b4fd75fb71d0861d7035ff42683405fbeeb5637b31c75efc0130f
MD5 a0e7732ccb23d6292f33a2cf2a8d4e73
BLAKE2b-256 5081cb5784f11c6adc670cfc70fc0a96dfbd764bbf3eece6f2c004cf4c9b6d19

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_tr-0.1-py3-none-any.whl:

Publisher: cd.yml on mgaitan/llm-tr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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