Skip to main content

poai: A comprehensive tool for Gettext PO (.po) translation files. It automates translations using artificial intelligence and provides seamless bidirectional conversion between PO and JSON formats.

Project description

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_plural and msgstr[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

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypoai-1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypoai-1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pypoai-1.0.tar.gz.

File metadata

  • Download URL: pypoai-1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pypoai-1.0.tar.gz
Algorithm Hash digest
SHA256 5f1f37a0f3da4eae48b87e6bee3adbb26cd863d9c424dd00795d1954e060e3e4
MD5 61ae73cbf5068071436a03b88a925457
BLAKE2b-256 4550c17427ad3b7857fbee02102c40d8cdc371fedbd269a5537e497e8ca79c55

See more details on using hashes here.

File details

Details for the file pypoai-1.0-py3-none-any.whl.

File metadata

  • Download URL: pypoai-1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pypoai-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b9627a65eca4ebd3249a03d58577930ec0f4b31d47335b0b796208f7cb534a5
MD5 4439d265317273360588519d9ffc0892
BLAKE2b-256 f2008a63306a96d419d5b0486092a71ab6bb114e653b24f58da12b6a8780c908

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page