Skip to content

PyLLM-PO is a command-line tool for translating .po files using OpenAI's language models.

Notifications You must be signed in to change notification settings

mctlisboa/PyLLM-PO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

PyLLM-PO

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.

Features

  • Automatic translation of .po files 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.

Installation

Ensure you have Python 3 installed, then install the dependencies:

pip install openai polib tqdm

Usage

Run 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/llmpo

Now you can run it from anywhere:

llmpo <input_file.po> [options]

Arguments

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).

Example Usage

Translate a .po file from English to Portuguese:

python llmpo.py theme.po --target-lang Portuguese --api-key YOUR_OPENAI_API_KEY

Specify an output file:

python llmpo.py theme.po -o translated.po --target-lang Portuguese

Use a custom OpenAI API host:

python llmpo.py theme.po --target-lang French --api-host "https://custom-api-host.com/v1"

Environment Variables

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"

License

This project is licensed under the MIT License.

Contributions

Pull requests and improvements are welcome! Feel free to submit issues or feature requests.

About

PyLLM-PO is a command-line tool for translating .po files using OpenAI's language models.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages