Files
ResourceTranslate/ui.py
2026-02-14 18:12:28 +01:00

92 lines
3.8 KiB
Python

"""
User interface components for Android XML Translation Tool
"""
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.prompt import Confirm
from models import TranslationBatch
class UI:
"""User interface handler"""
def __init__(self):
self.console = Console()
def show_header(self):
"""Display application header"""
self.console.print(Panel.fit("🌍 Android XML Translation Tool", style="bold blue"))
def show_processing_language(self, language: str):
"""Display current language being processed"""
self.console.print(f"\n[bold cyan]Processing language: {language}[/bold cyan]")
def show_processing_file(self, filename: str):
"""Display current file being processed"""
self.console.print(f"[dim]Processing file: {filename}[/dim]")
def show_processing_folder(self, folder: str):
"""Display current folder being processed"""
self.console.print(f"[dim]Processing folder: {folder}[/dim]")
def show_asset_count_check(self, count: int):
"""Display asset count check passed message"""
self.console.print(f"[green]✓ Asset count check passed: {count} .md files in all locales[/green]")
def show_missing_strings(self, count: int, filename: str):
"""Display count of missing strings"""
self.console.print(f"[yellow]Found {count} missing strings in {filename}[/yellow]")
def show_all_translated(self, filename: str):
"""Display message when all strings are already translated"""
self.console.print(f"[green]✓ {filename}: All strings are already translated[/green]")
def show_batch_approval(self, batch: TranslationBatch, translations: list[str]) -> bool:
"""Show batch translations for user approval"""
self.console.print(f"\n[bold]📝 Translation Batch Review[/bold]")
self.console.print(f"[dim]Target: {batch.target_language} | File: {batch.target_file}[/dim]\n")
# Create table for display
table = Table(show_header=True, header_style="bold magenta")
table.add_column("#", style="cyan", width=4)
table.add_column("Original", style="white")
table.add_column("Translation", style="green")
for i, (item, translation) in enumerate(zip(batch.items, translations)):
table.add_row(str(i + 1), item.value, translation)
self.console.print(table)
# Ask for approval
return Confirm.ask("\n[yellow]Approve these translations?[/yellow]", default=True)
def show_batch_skipped(self, batch_num: int):
"""Display message when batch is skipped"""
self.console.print(f"[yellow]⏭️ Batch {batch_num} skipped[/yellow]")
def show_batch_failed(self, batch_num: int):
"""Display message when batch translation fails"""
self.console.print(f"[red]❌ Translation failed for batch {batch_num}[/red]")
def show_batch_added(self, batch_num: int, filename: str):
"""Display message when batch is successfully added"""
self.console.print(f"[green]✅ Batch {batch_num} added to {filename}[/green]")
def show_warning(self, message: str):
"""Display warning message"""
self.console.print(f"[yellow]Warning: {message}[/yellow]")
def show_error(self, message: str):
"""Display error message"""
self.console.print(f"[red]Error: {message}[/red]")
def show_success(self, message: str):
"""Display success message"""
self.console.print(f"[bold green]✅ {message}[/bold green]")
def show_interrupted(self):
"""Display interruption message"""
self.console.print("\n[yellow]⚠️ Translation process interrupted by user[/yellow]")