A CLI tool for translating .po files using GPT models.
Project description
Python GPT-4 PO File Translator
This Python script provides a convenient tool for translating .po
files using OpenAI's GPT-4 model. It is designed to handle both bulk and individual translation modes, making it suitable for a wide range of project sizes and .po
file structures.
Features
- Bulk Translation Mode: Facilitates the translation of multiple text entries simultaneously, enhancing efficiency.
- Individual Translation Mode: Offers the flexibility to translate entries one at a time for greater precision.
- Configurable Batch Size: Users can set the number of entries to be translated in each batch during bulk translation.
- Comprehensive Logging: The script logs detailed information for progress monitoring and debugging purposes.
- Fuzzy Entry Exclusion: Provides the option to omit 'fuzzy' entries from translation in
.po
files. - Flexible API Key Configuration: Supports providing the OpenAI API key either through command-line arguments or a
.env
file.
Requirements
- Python 3.x
polib
libraryopenai
Python package
Installation
Via PyPI
You can install the gpt-po-translator
package directly from PyPI:
pip install gpt-po-translator
This command will install the package along with its dependencies.
Manual Installation
If you prefer to install manually or want to work with the latest code from the repository:
- Clone the repository:
git clone [repository URL]
- Navigate to the cloned directory and install the package:
pip install .
Usage
After installation, you can use gpt-po-translator
as a command-line tool:
gpt-po-translator --folder [path_to_po_files] --lang [language_codes] [--api_key [your_openai_api_key]] [--fuzzy] [--bulk] [--bulksize [batch_size]] [--folder-language]
--folder
: Path to the folder containing.po
files.--lang
: Comma-separated list of language codes for filtering.po
files.--api_key
: (Optional) Your OpenAI API key. If omitted, the script will look for it in the.env
file.--fuzzy
: (Optional) Flag to skip 'fuzzy' entries in translation.--bulk
: (Optional) Enable bulk translation mode.--bulksize
: (Optional) Set the batch size for translations in bulk mode (default is 50).--folder-language
: (Optional) Enable the script to infer the language from the directory structure of the.po
files.
Example
gpt-po-translator --folder ./locales --lang de,fr --api_key 'your_api_key_here' --bulk --bulksize 100 --folder-language
This command translates .po
files in the ./locales
folder to German and French, using the provided OpenAI API key, and processes 100 translations per batch in bulk mode. It also infers the language from the directory structure if necessary.
Logging
The script provides detailed logging that includes information about the files being processed, the number of translations, and batch details in bulk mode.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for gpt_po_translator-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d607e4569ce52669440882eb9c33e844d026c442f7b9eefa781b1db2574e791 |
|
MD5 | a365f029cdfb3959782147b6ff9c5a58 |
|
BLAKE2b-256 | 800c89ee966a5ecf8cce755f97a181db7b7e15cb751e4d436ee628c0290ebfff |