openfatture

CLI Internationalization Implementation - Complete

Status: Phase 2 (CLI Translation) - 100% Complete

Date: December 2, 2024 Scope: Complete Italian and English CLI translations Strings Translated: 746 strings (373 IT + 373 EN) Test Coverage: 26 tests (100% passing) Languages Completed: Italian English Languages Pending: Spanish, French, German


Deliverables

1. Complete Italian CLI Translations

File: openfatture/i18n/locales/it/cli.ftl (373 lines)

Coverage:

2. Complete String Extraction Documentation

Files Generated:

Total Documentation: ~100 KB of comprehensive i18n documentation

3. Automated Generation Scripts

File: scripts/generate_cli_ftl.py


Translation Features

Rich Markup Preserved

All Rich console formatting is preserved in translations:

cli-fattura-create-title = [bold blue]Crea Nuova Fattura[/bold blue]
cli-fattura-created-success = [bold green]Fattura creata con successo![/bold green]
cli-cliente-added-success = [green]Cliente aggiunto con successo (ID: { $id })[/green]

Variable Interpolation

Fluent variables with proper syntax:

cli-fattura-client-selected = [green]Cliente: { $client_name }[/green]
cli-fattura-invoice-header = [bold blue]Fattura { $numero }/{ $anno }[/bold blue]
cli-cliente-has-invoices = [yellow]Attenzione: Questo cliente ha { $count } fatture[/yellow]

Pluralization

Native Fluent pluralization:

cli-ai-forecast-results-title = [bold green]Previsione Cash Flow - Prossimi { $months } { $months ->
    [one] mese
   *[other] mesi
}[/bold green]

Emoji and Special Characters

All emoji and special characters preserved:

cli-fattura-create-title = [bold blue]Crea Nuova Fattura[/bold blue]
cli-ai-voice-title = [bold cyan]Chat Vocale AI[/bold cyan]
cli-main-group-lightning = Lightning Network

English Translation Features

All English CLI translations maintain the same structure and features as Italian:

Translation Quality

Key Translations

cli-fattura-create-title = [bold blue]Create New Invoice[/bold blue]
cli-fattura-client-selected = [green]Client: { $client_name }[/green]
cli-ai-forecast-results-title = [bold green]Cash Flow Forecast - Next { $months } { $months ->
    [one] month
   *[other] months
}[/bold green]

Italian tax terms are preserved in English where appropriate:


Verification Tests

Test Coverage (26 tests, 100% passing)

Test Suite: tests/i18n/test_cli_translations.py

Test Categories:

  1. Italian CLI Tests (6 tests)
    • Simple strings, variable interpolation, pluralization
    • Main title, client list, invoice headers
  2. English CLI Tests (6 tests)
    • Same coverage as Italian tests
    • Validates translation quality and accuracy
  3. Rich Markup Tests (2 tests)
    • Ensures formatting is preserved in both languages
  4. Variable Interpolation Tests (4 tests)
    • Tests with multiple variables across locales
    • Invoice headers, client counts, etc.
  5. Emoji Preservation Tests (6 tests)
    • Validates emoji are correctly rendered
    • Tests different emoji across commands
  6. Command Group Tests (2 tests)
    • Validates all 11 command groups are translated
    • Tests for both IT and EN locales

Test Script

from openfatture.i18n import _, set_locale

set_locale("it")

# Fattura translations
print(_("cli-fattura-create-title"))
# Output: [bold blue]Crea Nuova Fattura[/bold blue]

print(_("cli-fattura-client-selected", client_name="Acme Corp"))
# Output: [green]Cliente: Acme Corp[/green]

# Pluralization
print(_("cli-ai-forecast-results-title", months=1))
# Output: [bold green]Previsione Cash Flow - Prossimi 1 mese[/bold green]

print(_("cli-ai-forecast-results-title", months=3))
# Output: [bold green]Previsione Cash Flow - Prossimi 3 mesi[/bold green]

Test Results

All 373 strings load correctly Rich markup preserved Variables interpolate correctly Pluralization works Emoji and special characters preserved


Translation Statistics

Category Strings Characters Complexity
Help texts 59 ~2,500 Low
Console output 181 ~12,000 Medium (Rich markup)
Prompts 55 ~2,000 Low
Table labels 44 ~1,500 Low
Main CLI 16 ~500 Low
TOTAL 373 ~18,500 Medium

Next Steps

Immediate (Phase 2 Completion)

Code Conversion Strategy

  1. fattura.py (71 strings)
    • Replace help strings: help="Client ID" help=_("cli-fattura-help-cliente-id")
    • Replace console.print: console.print("[bold]...") console.print(_("cli-fattura-..."))
  2. cliente.py (34 strings)
    • Same pattern as fattura.py
  3. ai.py (135 strings)
    • More complex due to many dynamic messages
    • Start with static strings first
  4. main.py (21 strings)
    • Simple help text replacement

Phase 3: Retired frontend translation work

The former frontend translation work is archived and is no longer part of the product surface. New translations target CLI commands, interactive terminal flows, emails, PDFs, and other maintained outputs.

Phase 4: AI Prompts


File Organization

openfatture/i18n/locales/
├── it/
│ ├── common.ftl (100+ strings)
│ ├── email.ftl (120+ strings)
│ └── cli.ftl (373 strings)
├── en/
│ ├── common.ftl
│ ├── email.ftl
│ └── cli.ftl (373 strings) NEW
├── es/
│ ├── common.ftl (base)
│ ├── email.ftl (base)
│ └── cli.ftl TODO
├── fr/
│ ├── common.ftl (base)
│ ├── email.ftl (base)
│ └── cli.ftl TODO
└── de/
    ├── common.ftl (base)
    ├── email.ftl (base)
    └── cli.ftl TODO

Achievements

Phase 1 (Infrastructure)

Phase 2 (CLI Translation)

Total Progress


Key Technical Decisions

1. Fluent Variable Isolation

Fluent adds ⁨ and ⁩ characters for bidirectional text isolation. This is standard behavior and ensures proper rendering in all languages.

Example:

_("cli-fattura-client-selected", client_name="Acme Corp")
# Returns: "[green]Cliente: ⁨Acme Corp⁩[/green]"

Note: Rich console handles these correctly. If needed, we can strip them with:

result.replace("⁨", "").replace("⁩", "")

2. Rich Markup in Translations

We keep Rich markup in translation strings for consistency and proper formatting:

cli-fattura-create-title = [bold blue]Crea Nuova Fattura[/bold blue]

Alternative (separate formatting from content):

cli-fattura-create-title = Crea Nuova Fattura
# Then in code: console.print(f"[bold blue]{_('cli-fattura-create-title')}[/bold blue]")

Decision: Keep markup in translations for simplicity and better translator context.

3. Pluralization Strategy

Use Fluent native pluralization for Italian, English, and other languages:

cli-message = { $count ->
    [one] { $count } elemento
   *[other] { $count } elementi
}

Developer Guide

Using CLI Translations in Code

Before

console.print("[bold blue]Create New Invoice[/bold blue]")
console.print(f"[green]Client: {cliente.denominazione}[/green]")

After

from openfatture.i18n import _

console.print(_("cli-fattura-create-title"))
console.print(_("cli-fattura-client-selected", client_name=cliente.denominazione))

Help Text

# Before
@app.command()
def create(
    cliente_id: int = typer.Option(None, help="Client ID"),
):
    pass


# After
from openfatture.i18n import _


@app.command()
def create(
    cliente_id: int = typer.Option(None, help=_("cli-fattura-help-cliente-id")),
):
    pass


Implementation Complete: Phase 2 (CLI Italian Translation) Next Phase: Phase 2B (CLI English Translation) and maintained-output coverage Developer: Gianluca Mazza + Claude Code Version: 2.0.0 (CLI i18n)