https://github.com/rgglez/gettext-cloud-translator
gettext-cloud-translator
https://github.com/rgglez/gettext-cloud-translator
ai azure-translate azure-translation-services gettext openai-translate translator
Last synced: 2 months ago
JSON representation
gettext-cloud-translator
- Host: GitHub
- URL: https://github.com/rgglez/gettext-cloud-translator
- Owner: rgglez
- License: mit
- Created: 2024-08-01T07:27:56.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-03-05T20:41:40.000Z (3 months ago)
- Last Synced: 2025-03-05T21:53:05.893Z (3 months ago)
- Topics: ai, azure-translate, azure-translation-services, gettext, openai-translate, translator
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# gettext-cloud-translator
[](https://opensource.org/license/mit)


## Gettext Cloud Translator
This program allows to translate .po files, as used by [gettext](https://www.gnu.org/software/gettext/) using different cloud services. This software was inspired by [pescheckit/python-gpt-po](https://github.com/pescheckit/python-gpt-po). Currently it works with Microsoft Azure Translator, but the plan is to rewrite the functionality of the ChatGPT backend.
## Notes
This is an initial commit to initialize the repository. This version is experimental.
## 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.## Requirements
- Python 3.x
- `polib` library
- `openai` Python package## API Key Configuration
The `gpt-po-translator` supports two methods for providing OpenAI API credentials:
1. **Environment Variable**: Set your OpenAI API key as an environment variable named `OPENAI_API_KEY`. This method is recommended for security and ease of API key management.
```bash
export OPENAI_API_KEY='your_api_key_here'
```2. **Command-Line Argument**: Pass the API key as a command-line argument using the `--api_key` option.
```bash
gpt-po-translator --folder ./locales --lang de,fr --api_key 'your_api_key_here' --bulk --bulksize 100 --folder-language
```Ensure your API key is kept secure and not exposed in shared or public spaces.
## Installation
### Manual Installation
For manual installation or to work with the latest code from the repository:
1. Clone the repository:
```bash
git clone [repository URL]
```
2. Navigate to the cloned directory and install the package:
```bash
pip install .
```## Usage
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] [--source-language [Language]]
```### 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.
## Logging
The script logs detailed information about the files being processed, the number of translations, and batch details in bulk mode.
## Notes
* You can find the name of the OpenAI ChatGPT models and their pricing [here](https://openai.com/api/pricing/).
* Learn about [gettext](https://www.gnu.org/software/gettext/) and the [format of PO files](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html).## License
Read the [MIT LICENSE](LICENSE) file.