Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

Use Polyglot UI to translate

Polyglot UI is a smart translation workflow tool that filters untranslated strings from .po files by checking which Python objects and modules are actually imported by your app, then translates them using Google Gemini API.

When useful

Use Polyglot UI when translating Lino applications that depend on shared packages like lino and lino_xl. These packages contain thousands of strings, but each app only uses a subset. Polyglot UI extracts only the strings your app actually needs.

Features

  • Smart filtering: Extracts only strings from imported modules and accessible objects

  • Automated translation: Uses Google Gemini API with batch processing and resume capability

  • Three extraction modes:

    • helptexts - Filters help texts by checking object accessibility via sys.modules

    • modules - Filters strings by checking occurrence comments against imported modules

    • html - Extracts all untranslated HTML template strings

  • Automatic updates: Updates and compiles .po files after translation

Quick Start

  1. Install:

    pip install polyglot-ui
    
  2. Set API key:

    export GEMINI_API_KEY="your-key-here"
    

    Get your key from https://ai.google.dev/

  3. Standard workflow:

    # Generate .po files
    inv mm
    
    # Extract untranslated strings (requires Django context)
    python manage.py run $(which polyglot-ui) helptexts \
        -p lino -l lino -L bn -o helptexts.json
    python manage.py run $(which polyglot-ui) modules \
        -p lino -l lino -L bn -o modules.json
    
    # Extract HTML (no Django context needed)
    polyglot-ui html -l lino -L bn -o html.json
    
    # Translate
    polyglot-ui translate -i helptexts.json -o t_helptexts.json
    polyglot-ui translate -i modules.json -o t_modules.json
    polyglot-ui translate -i html.json -o t_html.json
    
    # Update .po files and compile
    polyglot-ui update -t t_helptexts.json t_modules.json t_html.json \
        -l lino --lang bn
    polyglot-ui compile path/to/locale_root/locale/bn/LC_MESSAGES/django.po
    

Commands requiring Django context

Use python manage.py run $(which polyglot-ui) for:

  • helptexts - Needs sys.modules to check object accessibility

  • modules - Needs sys.modules to check module imports (unless --all flag)

Other commands (html, translate, update, compile) run standalone.

See the Polyglot UI repository for complete documentation.