poai
A .po to JSON and JSON to .po converter with optional AI translation support.
Features
- Bidirectional conversion:
.po→ JSON and JSON →.po - AI-powered translation (optional): Use Google Gemini to fill translations
- Empty translation filtering: Skip untranslated messages or process all
- Plural form support: Handles
msgid_pluralandmsgstr[n] - Batch processing: Translate large files in configurable chunks
- Fallback to source: Automatically fall back to source text for missing translations
- Replace from external JSON: Bulk update translations from a JSON file
- Programmatic and CLI usage: Use as a Python library or via command-line script
Installation
pip install poai
Usage
As a Python library
from poai import PoJsonConverter
# Initialize converter
conv = Poai(
encoding='utf-8', # File encoding
show_empty=False, # Only include translated messages
api_key='YOUR_API_KEY' # Optional Gemini API key for AI translation
)
# Read .po and convert to JSON
data = conv.read_po('locale/tr/LC_MESSAGES/django.po')
conv.save_json('translations.json')
# Load JSON, edit or replace translations, then save back to .po
conv.read_json('translations.json')
conv.set_messages(data['messages'])
conv.save_po('locale/tr/LC_MESSAGES/new.po')
# AI translate missing messages and save results
conv.translate_with_ai(only_empty=True)
conv.save_json('translations_with_ai.json')
CLI (if enabled)
# Read PO, translate all strings, and write JSON
poai read-po --input locale/tr/app.po --show-empty --api-key $GEMINI_KEY \
| poai save-json --output translations.json
# Replace translations from JSON and write updated PO
poai read-json --input translations.json \
| poai save-po --output locale/tr/app_updated.po
Development
# Clone and install dev requirements
git clone https://github.com/cagrigungor/poai.git
cd poai
pip install -e .[dev]
# Run tests
pytest
License
This project is licensed under the MIT License. See LICENSE for details.
Author
Hasan Çağrı Güngör
✉️ iletisim@cagrigungor.com
🔗 https://github.com/cagrigungor/poai
Release files for pypoai 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pypoai-1.0.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pypoai-1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.1 kB
Release files / pypoai-1.0.tar.gz
| Download URL | pypoai-1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f1f37a0f3da4eae48b87e6bee3adbb26cd863d9c424dd00795d1954e060e3e4
|
|
BLAKE2b-256 checksum How to use checksums |
4550c17427ad3b7857fbee02102c40d8cdc371fedbd269a5537e497e8ca79c55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / pypoai-1.0-py3-none-any.whl
| Download URL | pypoai-1.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b9627a65eca4ebd3249a03d58577930ec0f4b31d47335b0b796208f7cb534a5
|
|
BLAKE2b-256 checksum How to use checksums |
f2008a63306a96d419d5b0486092a71ab6bb114e653b24f58da12b6a8780c908
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|