Skip to main content

ailingo: A CLI tool for translating local files using generative AI (LLM)

ailingo is a command-line interface (CLI) tool that uses generative AI to translate local files into various languages.

Releases CI MIT License

English | 日本語 | 简体中文 | 繁体中文 | Español

Overview

It is designed to enable developers, translators, and content creators to efficiently localize their files.

Key Features:

  • Flexible file handling: Translate multiple files at once.
  • Wide language support: Freely specify the source and target languages.
  • Generative AI model selection: Choose from various generative AI models available through litellm, including ChatGPT, Gemini, and Anthropic.
  • Customizable output: Control the names and save locations of translated files.
  • Adding translation requests: Add requests for nuances in translation, such as casual tone.
  • Rewrite mode: Rewrite text in the same language with spelling/grammar correction or adjust the writing style as requested.
  • Editor mode: Translate text directly in an editor.
  • URL mode: Download and translate a web page.

Installation

Prerequisites:

  • Python 3.11

Quick Start:

export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
pip install ailingo
ailingo my_document.txt --target ja

Detailed setup procedure:

1. Setting up litellm:

This program uses LiteLLM to access generative AI. LiteLLM is designed to work with a variety of providers. Please create an account with the provider of the generative AI model you wish to use, and obtain an API key.

Please refer to the LiteLLM documentation for detailed setup instructions. Here are some examples of setting up typical API keys:

# Default: OpenAI (gpt-4o, etc.)
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"

# VertexAI (Gemini, etc.)
# Run `gcloud auth application-default login` or set `GOOGLE_APPLICATION_CREDENTIALS`
export VERTEXAI_PROJECT="your-google-project-id"
export VERTEXAI_LOCATION="us-central1"

# Anthropic (haiku, opus, sonnet, etc.)
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"

2. Installing ailingo:

pip install ailingo
# If you want to use VertexAI (Gemini etc.)
pip install 'ailingo[google]'
# If you want to use AWS (Bedrock)
pip install 'ailingo[aws]'
# Or install all dependencies
pip install 'ailingo[all]'

Usage

Basic translation:

ailingo <file path> --target <target language>

Example:

ailingo my_document.txt --target ja

This will translate my_document.txt into Japanese and save it as my_document.ja.txt. By default, it will be saved in the same folder in the format {stem}.{target}{suffix}.

File name estimation by specifying the source language:

ailingo /path/to/en/my_document.txt --source en --target ja

This will translate my_document.txt into Japanese and save it as /path/to/ja/my_document.txt. This feature replaces the source language code with the target language code if the file name or directory name contains the source language code.

  • Example: document.en.txt → document.ja.txt
  • Example: locales/en/LC_MESSAGES/message.po → locales/ja/LC_MESSAGES/message.po

Note: This automatic estimation does not apply if you specify an output file name pattern with the --output option.

Multiple files and target languages:

ailingo file1.txt file2.html --target ja,es,fr

This will translate file1.txt and file2.html into Japanese, Spanish, and French.

Specifying additional translation requests:

ailingo my_document.txt --target de --request "Please make it as casual as possible, with some jokes in between."

This will request to make the translation of my_document.txt into German as casual as possible, with some jokes added.

Rewrite mode: Modifying the style of the text in the same language

ailingo my_document.txt

If you do not specify a target language, the existing my_document.txt will be rewritten in the same language. Other options can be specified in the same way as for translation.

By default, it will correct spelling and grammatical errors, but you can also use the --request option to add more specific requests.

Editor mode: Translate without specifying a file

ailingo -e

In editor mode, a temporary file is opened in an editor (vi by default) for manual editing before translation. After editing, the saved content is used for translation.

Other options can be used in combination:

  • The target language can be specified with --target.
  • Style modification requests can be added with --request.
  • The translation result is displayed on standard output by default, but an output file can be specified with --output.

URL mode: Translating web pages

ailingo -u <URL> --target <target language>

In URL mode, ailingo extracts the text content of the web page at the specified URL, translates it, and outputs it in Markdown format.

Other options can be used in combination:

Specifying the Generative AI Model:

ailingo my_document.txt --target de --model gemini-1.5-pro

This will translate my_document.txt into German using Google Gemini Pro.

Streaming Output (Experimental)

ailingo my_document.txt --target ja --stream

The --stream option enables streaming output, which displays the translation results in real time. Streaming output is disabled by default.

Customizing the output file name:

ailingo my_document.txt --target es --output "{parent}/{stem}_translated.{target}{suffix}"

This will translate my_document.txt into Spanish and save it as my_document_translated.es.txt.

ailingo /path/to/en/my_document.txt --target ja --output "{parents[1]}/{target}/{name}"

This will translate path/to/en/my_document.txt into Japanese and save it as path/to/ja/my_document.txt.

The string specified for --output is interpreted by the format function. The following variables are available:

Variable Name Value Type Example
{stem} Part of the input file excluding the extension str my_document
{suffix} Extension of the input file (including the dot) str .txt
{suffixes} List of extensions of the input file (including the dot) list[str] ['.ja', '.txt']
{name} File name of the input file including the extension str my_document.txt
{parent} Parent directory of the input file str /path/to/en
{parents} List of parent directories of the input file list[str] ['/path/to', '/path']
{target} Target language str ja
{source} Source language (only if specified) Optional[str] en

For other variables, please refer to the Pathlib documentation.

Detailed options:

For more advanced usage, please use the help command:

ailingo --help

License

This project is distributed under the MIT License.

Disclaimer

This tool utilizes generative AI, but the quality of the translation depends on the selected AI model and input text. It is recommended to review the translation results and make corrections as needed.

Metadata

Release files for ailingo 0.4.0

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

Source distribution (sdist)

Source distribution for ailingo 0.4.0
File Size Uploaded Provenance
ailingo-0.4.0.tar.gz 13.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ailingo 0.4.0
File Interpreter ABI Platform
ailingo-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / ailingo-0.4.0.tar.gz

Download URL ailingo-0.4.0.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2821d7f8deb6b75a296d3152e427e2d85e31c7e213e708f5f4989907c1264712
BLAKE2b-256 checksum
How to use checksums
920f3eeb2d62c1ca1fecd3df0d20896184d95f0ec29fbbe23679cd9927a6f072
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release files / ailingo-0.4.0-py3-none-any.whl

Download URL ailingo-0.4.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e59754242f71cf4f98f55fcec11965808aec4411eb0424862a89782f081e6ead
BLAKE2b-256 checksum
How to use checksums
5ac90577c93cedb41ed770d5fd703321dfa7b6ca0a107c210f2cc8e68ac62937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Security for ailingo 0.4.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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