Skip to content

thegeek/translAItor

Repository files navigation

translaitor

License: MIT Python Version

A CLI and Python library for translating and improving text using Google Gemini models.


Table of Contents


Features

  • Translate and improve text from any language to professional English
  • Command-line interface (CLI) for easy translation from stdin to stdout
  • Python API for integration in your own scripts
  • Supports Google Gemini models for both text and image generation
  • List available Gemini models from the CLI
  • Clipboard translation scripts for Linux and Windows

Installation

  1. Clone the repository:
    git clone <your-repo-url>
    cd translAItor
  2. Install dependencies: Make sure you are using Python 3.12 or 3.13 (as specified in pyproject.toml).
    pip install .
    Or, for development:
    pip install -e .

Building a Wheel

To build a wheel distribution:

pip install build
python -m build --wheel

The wheel file will be created in the dist/ directory.

Dependencies

  • google-genai==1.21.1
  • python-dotenv==1.0.1
  • Pillow==11.1.0
  • click==8.1.7

Environment Setup

You must set your Google Gemini API key in your environment. You can do this by creating a .env file in the project root:

GEMINI_API_KEY=your_api_key_here

Or export it directly:

export GEMINI_API_KEY=your_api_key_here

Usage

GUI

After installation, you can launch the graphical clipboard translator with:

python -m translaitor.gui

or, if you have an entry point installed:

translaitor-gui

Features:

  • Input and output text areas for translation
  • Translate Text and Copy Output to Clipboard buttons are side by side and only as wide as their labels
  • The Copy Output to Clipboard button is automatically disabled if the output area is empty
  • Status bar shows input/output character counts, dry run mode, and API key status
  • Dry run mode copies input to output without calling the API
  • Gemini API key status is shown at the bottom

CLI

After installation, you can use the CLI directly:

Translate text from standard input and print the result to standard output:

translaitor translate

You can also redirect files:

translaitor translate input.txt output.txt

List available Gemini models:

translaitor list-models

Example CLI Session

echo "Ciao, come stai?" | translaitor translate
# Output: How are you?

Clipboard Translation Scripts

  • Linux: Use translate_clipboard.sh to translate clipboard contents and copy the result back. Requires xclip and notification support.
  • Windows: Use translate_clipboard.ps1 (requires the BurntToast module for notifications) for the same functionality. See script comments for details.

Python API

You can use the translation functionality in your own scripts:

from translaitor.ai_client import translate_call, TRANSLATING_PROMPT

prompt = "Ciao, come stai?"
result = translate_call(TRANSLATING_PROMPT.format(to_translate=prompt))
print(result)

List Models from Python

from translaitor.ai_client import list_gemini_models
models = list_gemini_models()
for name, desc in models:
    print(f"{name}: {desc}")

Model Information

You can view a list of available Gemini models using the CLI (translaitor list-models) or by checking the models.txt file in this repository for descriptions and details.

Troubleshooting & FAQ

Q: I get an error about missing the API key.

  • Make sure you have set GEMINI_API_KEY in your .env file or environment.

Q: The CLI command is not found after install.

  • Make sure your Python environment's bin/Scripts directory is in your PATH.
  • Try pip install -e . from the project root.

Q: How do I get notifications on Windows?

  • The PowerShell script uses the BurntToast module. Install it with:
    Install-Module -Name BurntToast -Force

Q: How do I update the list of models?

  • Run translaitor list-models to fetch the latest from the Gemini API.

License

MIT License

Contact

For questions, suggestions, or support, please open an issue on the repository or contact the maintainer at [your-email@example.com].

About

A CLI and Python library for translating and improving text using Google Gemini models.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors