PyLLM-PO is a command-line tool for translating .po files using OpenAI's language models. It is designed for translating WordPress themes and plugins efficiently while ensuring consistency in translation output.
- Automatic translation of
.pofiles using OpenAI's LLM. - Supports both singular and plural translations.
- Configurable OpenAI model and API host.
- Retry mechanism for failed API calls.
- Easily configurable via CLI arguments.
Ensure you have Python 3 installed, then install the dependencies:
pip install openai polib tqdmRun the script from the command line:
python llmpo.py <input_file.po> [options]Alternatively, you can make it executable and run it directly:
chmod +x llmpo.py
./llmpo.py <input_file.po> [options]If you want to use it globally, move it to a directory in your PATH:
mv llmpo.py /usr/local/bin/llmpo
chmod +x /usr/local/bin/llmpoNow you can run it from anywhere:
llmpo <input_file.po> [options]| Argument | Description |
|---|---|
input_file |
Path to the input .po file (required). |
-o, --output_file |
Path to the output .po file (default: overwrites input file). |
--source-lang |
Source language (default: English). |
--target-lang |
Target language (default: Portuguese). |
--model |
OpenAI model to use (default: gpt-4o-mini). |
--api-key |
OpenAI API key (or set via OPENAI_API_KEY environment variable). |
--api-host |
OpenAI API host (default: https://api.openai.com/v1). |
--max-retries |
Maximum number of retries for API calls (default: 5). |
Translate a .po file from English to Portuguese:
python llmpo.py theme.po --target-lang Portuguese --api-key YOUR_OPENAI_API_KEYSpecify an output file:
python llmpo.py theme.po -o translated.po --target-lang PortugueseUse a custom OpenAI API host:
python llmpo.py theme.po --target-lang French --api-host "https://custom-api-host.com/v1"Instead of passing the API key in the command line, you can set it as an environment variable:
export OPENAI_API_KEY="your-api-key"This project is licensed under the MIT License.
Pull requests and improvements are welcome! Feel free to submit issues or feature requests.