#!/usr/bin/env python3 """Riempie il catalogo italiano di harbour-thinq. - aggiunge language="it_IT" all'intestazione (senza, lupdate non lo aggiorna piu'); - sostituisce il blocco INTERO per ogni voce (mai solo il tag di apertura: un edit parziale rompe il parse di lrelease). Uso: python3 scripts/fill_translations.py """ from __future__ import annotations import re import sys import xml.etree.ElementTree as ET from pathlib import Path TS = Path(__file__).resolve().parent.parent / "translations" / "harbour-thinq-it.ts" IT = { "No data": "Nessun dato", "Delayed stop": "Stop ritardato", "Delayed stop…": "Stop ritardato…", "Set": "Imposta", "The machine will stop on its own after the chosen time, then resume its programme.": "La macchina si ferma da sola allo scadere del tempo scelto, poi riprende il programma.", "Refresh": "Aggiorna", "Switch off": "Spegni", "Wake the display up": "Risveglia il display", "Settings": "Impostazioni", "Not up to date": "Non aggiornato", "Not configured": "Da configurare", "Enter the LG access token in Settings and pick your machine.": "Inserisci la chiave di accesso LG nelle Impostazioni e scegli la macchina.", "of %1": "su %1", "Cycle": "Ciclo", "Remote start": "Avvio a distanza", "on": "attivo", "off": "spento", "To send commands, switch remote start on from the machine panel.": "Per inviare comandi, accendi l'avvio a distanza dal pannello della macchina.", "LG account": "Account LG", "The access token comes from connect-pat.lgthinq.com and stays on this phone only. " "If LG starts refusing it, paste a new one here.": "La chiave di accesso si crea su connect-pat.lgthinq.com e resta solo su questo " "telefono. Se LG non la accetta piu', incollane una nuova qui.", "Access token": "Chiave di accesso", "paste the token": "incolla la chiave", "Country code": "Paese", "Save the token": "Salva la chiave", "Machine": "Macchina", "Find my machines": "Trova le macchine", "Selected: %1": "Scelta: %1", "Language": "Lingua", "System": "Sistema", "Version %1": "Versione %1", "My machines": "Le mie macchine", "Updating…": "Aggiornamento…", "%1 found": "%1 trovate", "First setup": "Primo avvio", "Connect": "Collega", "Not connected": "Non collegata", "No machine found yet. Pull down to search again.": "Nessuna macchina trovata. Trascina in basso per cercare di nuovo.", "Washing finished": "Lavaggio finito", "Machines": "Macchine", "The access token is missing": "Manca la chiave di accesso", "No machine to command": "Nessuna macchina da comandare", "Washing machine": "Lavatrice", "Start": "Avvia", "Stop": "Ferma", "Resume": "Riprendi", "Enter the access token first": "Inserisci prima la chiave di accesso", "Machine selected": "Macchina scelta", "No data from the machine yet": "Ancora nessun dato dalla macchina", "No washing machine found on this account": "Nessuna lavatrice trovata su questo account", "Machines found: %1": "Macchine trovate: %1", "Command sent": "Comando inviato", "Set the access token and the machine first": "Imposta prima la chiave di accesso e la macchina", "Remote start is off on the machine: switch it on from its panel": "L'avvio a distanza e' spento sulla macchina: accendilo dal pannello", "Updated at %1": "Aggiornato alle %1", "The access token is no longer valid: enter a new one in Settings": "La chiave di accesso non e' piu' valida: inseriscine una nuova nelle Impostazioni", "Too many requests to LG: slowing down": "Troppe richieste a LG: rallento gli aggiornamenti", "The washing machine is not connected (switched off or offline)": "La lavatrice non e' collegata (spenta o senza rete)", "The machine does not accept this command": "La macchina non accetta questo comando", "LG error %1: %2": "Errore LG %1: %2", "No answer from the LG cloud: %1": "Nessuna risposta dal cloud LG: %1", "The LG cloud refused the request (HTTP %1)": "Il cloud LG ha rifiutato la richiesta (HTTP %1)", "Washing": "In lavaggio", "Rinsing": "In risciacquo", "Spinning": "In centrifuga", "Drying": "In asciugatura", "Cooling down": "Raffreddamento", "Refreshing": "Rinfrescando", "Steam softening": "Ammorbidente a vapore", "Detecting the load": "Rilevamento del carico", "Delayed start": "Partenza ritardata", "Rinse hold": "Ammollo", "Paused": "In pausa", "Finished": "Fine", "Ready": "Pronta", "Off": "Spenta", "Standby": "In attesa", "Error": "Errore", } def main() -> int: text = TS.read_text(encoding="utf-8") # language: senza, lupdate rifiuta di aggiornare il file in futuro. if 'language="' not in text: text = text.replace('', '', 1) else: text = re.sub(r'language="[^"]*"', 'language="it_IT"', text, count=1) missing: list[str] = [] def repl(match: re.Match) -> str: block = match.group(0) src = re.search(r"(.*?)", block, re.S) if not src: return block source = src.group(1) it = IT.get(source) if it is None: missing.append(source) return block # si sostituisce il blocco INTERO, non solo il tag new_block = re.sub(r"", f"{it}", block, flags=re.S) if new_block == block: new_block = block.replace("", f" {it}\n ") return new_block text = re.sub(r".*?", repl, text, flags=re.S) TS.write_text(text, encoding="utf-8") # validazione XML: un edit a mano malformato ferma lrelease con messaggi oscuri ET.parse(TS) if missing: print(f"ATTENZIONE: {len(missing)} voci senza traduzione:", file=sys.stderr) for m in missing: print(" -", m, file=sys.stderr) return 1 print("catalogo italiano completo e XML valido") return 0 if __name__ == "__main__": raise SystemExit(main())