Skip to content

Commit

Permalink
Changed README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pescheck-bram committed Aug 21, 2024
1 parent e98d4a9 commit 6c89d96
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# 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.
This Python script provides a comprehensive tool for translating `.po` files using OpenAI's GPT-4 model. It is designed to accommodate both bulk and individual translation modes, making it suitable for a wide range of project sizes and `.po` file structures.

## Features

- **Bulk Translation Mode**: Enhances efficiency by facilitating the translation of multiple text entries simultaneously.
- **Individual Translation Mode**: Offers the flexibility to translate entries one at a time for greater precision.
- **Configurable Batch Size**: Allows users to set the number of entries to be translated in each batch during bulk translation.
- **Comprehensive Logging**: Logs detailed information for progress monitoring and debugging purposes.
- **Fuzzy Entry Exclusion**: Enables 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.
- **Bulk Translation Mode**: Enhances efficiency by translating multiple text entries simultaneously. Ideal for large `.po` files.
- **Individual Translation Mode**: Offers flexibility to translate entries one at a time, ensuring precise translation. Useful for complex or nuanced content.
- **Configurable Batch Size**: Users can set the number of entries to be translated per batch during bulk translation, allowing for optimized API usage.
- **Fuzzy Entry Management**: Automatically handles 'fuzzy' entries by removing fuzzy flags, ensuring that only verified translations are processed.
- **Language Inference from Folder Structure**: Optionally infers the target language based on the folder structure of the `.po` files, streamlining the translation process.
- **Translation Validation and Retry Logic**: Built-in mechanisms validate translations, retrying where necessary to avoid incorrect or overly verbose translations.
- **Comprehensive Logging**: Detailed logging for progress monitoring, debugging, and ensuring transparency in the translation process.
- **Flexible API Key Configuration**: Supports providing the OpenAI API key via command-line arguments or environment variables for enhanced security and ease of use.
- **Retry Mechanism for Failed Translations**: Automatically retries failed translations up to three times, reducing the chance of incomplete or incorrect outputs.
- **Post-Processing for Translations**: Translations are reviewed to ensure they are concise and free from unnecessary explanations or repeated content.

## Requirements

- Python 3.x
- `polib` library
- `openai` Python package
- `tenacity` library (for retry mechanisms)
- `python-dotenv` (for environment variable management)

## API Key Configuration

Expand Down Expand Up @@ -72,12 +78,31 @@ gpt-po-translator --folder [path_to_po_files] --lang [language_codes] [--api_key
gpt-po-translator --folder ./locales --lang de,fr --api_key 'your_api_key_here' --bulk --bulksize 40 --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.
This command translates `.po` files in the `./locales` folder to German and French, using the provided OpenAI API key, and processes 40 translations per batch in bulk mode. It also infers the language from the folder structure.

### Command-Line Options

- `--folder`: Specifies the input folder containing `.po` files.
- `--lang`: Comma-separated language codes to filter `.po` files.
- `--fuzzy`: Remove fuzzy entries before processing.
- `--bulk`: Enables bulk translation mode for faster processing.
- `--bulksize`: Sets the batch size for bulk translation. Default is 50.
- `--model`: Specifies the OpenAI model to use for translations. Default is `gpt-3.5-turbo-0125`.
- `--api_key`: OpenAI API key. Can be provided through the command line or as an environment variable.
- `--folder-language`: Infers the target language from the folder structure.

## Logging

The script logs detailed information about the files being processed, the number of translations, and batch details in bulk mode.
The script logs detailed information about the files being processed, the number of translations, and batch details in bulk mode. The logs are essential for monitoring the progress, debugging issues, and ensuring all translations are handled correctly.

## Error Handling and Retries

The translation process includes robust error handling and retries:

- **Failed Translations**: If a translation fails, the script will automatically retry up to three times.
- **Empty Translations**: If an empty translation is returned, the script will attempt to translate the text again using a different approach.
- **Lengthy or Incorrect Translations**: Translations that are too long or contain explanations instead of direct translations are flagged and retried.

## License

[MIT](LICENSE)
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

0 comments on commit 6c89d96

Please sign in to comment.