Files
harbour-thinq/scripts/fill_translations.py
T
kaneda b5f6e79146 Prima versione di ThinQ: stato e comandi della lavasciuga via cloud LG
- elenco delle macchine e stato in lettura, fasi tradotte in italiano
- avvio, stop, spegnimento, ripresa e stop ritardato da 3 a 19 ore
- chiave di accesso custodita solo sul telefono, nel file privato dell'app
- 44 verifiche automatiche sul nucleo (scripts/test-core.sh)
- interfaccia italiana o inglese secondo la lingua del telefono
2026-10-12 12:03:23 +02:00

147 lines
5.7 KiB
Python

#!/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 <translation> 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",
"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('<TS version="2.1">', '<TS version="2.1" language="it_IT">', 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"<source>(.*?)</source>", 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 <translation> INTERO, non solo il tag
new_block = re.sub(r"<translation.*?</translation>",
f"<translation>{it}</translation>", block, flags=re.S)
if new_block == block:
new_block = block.replace("</message>",
f" <translation>{it}</translation>\n </message>")
return new_block
text = re.sub(r"<message>.*?</message>", 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())