mix gettext_ops.translate (gettext_ops v0.1.1)

View Source

Update msgstr (translations) in .po files from various input sources.

This is the most important command for the LLM workflow. It enables bulk translation updates without manually editing .po files. Accepts translations in a simple format: msgid = msgstr (one per line).

Usage

mix gettext_ops.translate [options]

Input Sources

The task accepts translation input from multiple sources:

  1. stdin (most common for LLM workflows)

     mix gettext_ops.translate --locale sv <<EOF
     Sign In = Logga in
     Sign Out = Logga ut
     EOF
    
  2. File

     mix gettext_ops.translate --locale sv --file translations.txt
    
  3. Pipe

     echo "Welcome = Välkommen" | mix gettext_ops.translate --locale sv
    

Input Format

Each line should contain a msgid and msgstr separated by =:

Sign In = Logga in
Sign Out = Logga ut
Welcome = Välkommen
Error: Invalid input = Fel: Ogiltig inmatning

Empty lines and lines starting with # (comments) are ignored.

Options

  • --locale / -l - (required) Target locale (e.g., "sv", "en")
  • --domain / -d - Gettext domain (defaults to configured default_domain)
  • --file / -f - Input file (uses stdin if not provided)
  • --force - Continue even if some msgids are not found (show warnings instead of failing)

Examples

# From stdin (heredoc) - most common
mix gettext_ops.translate --locale sv <<EOF
Sign In = Logga in
Sign Out = Logga ut
EOF

# From file
mix gettext_ops.translate --locale sv --file translations.txt

# From pipe
echo "Welcome = Välkommen" | mix gettext_ops.translate --locale sv

# With force flag (ignore missing msgids)
mix gettext_ops.translate --locale sv --force --file partial.txt

# LLM workflow example
mix gettext_ops.list_untranslated --locale sv --json --limit 10 | \
  llm "translate to Swedish" | \
  mix gettext_ops.translate --locale sv

Atomic Updates

Updates are performed atomically by writing to a temporary file and then renaming it. This ensures the .po file is never left in a corrupted state.

Error Handling

By default, the command fails if any msgid is not found in the .po file. Use --force to continue with partial updates and get warnings instead.