Skip to content

Commit 9055125

Browse files
belinea4071claude
andcommitted
Localize dashboard template section titles (#60)
Add _translate_dashboard() to DashboardGenerator that translates mushroom-title-card titles and subtitles to the user's HA language when generate_dashboard is called. Translations for: German, French, Spanish, Italian, Dutch. Covers ~25 section titles: EV Charging, Battery Management, SOC Zone Configuration, Cost Tracking, System Health, etc. Uses hass.config.language to detect system language. Walks the parsed YAML dict and replaces title/subtitle/primary strings from a lookup table. Closes #60 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 979c0a6 commit 9055125

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

features/dashboard_generator.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,83 @@ def __init__(self, hass: HomeAssistant):
3030
self._dashboard_template_path = basic_path
3131
self._is_premium = False
3232

33+
# Dashboard section title translations for generate_dashboard (#60)
34+
_DASHBOARD_TRANSLATIONS = {
35+
"de": {
36+
"EV Charging": "EV-Laden", "Surplus Control": "Überschusssteuerung",
37+
"Battery Management": "Batterieverwaltung", "Heat Pump & Hot Water": "Wärmepumpe & Warmwasser",
38+
"Solar & Power": "Solar & Leistung", "Tariff & Pricing": "Tarif & Preise",
39+
"Today's Schedule": "Tagesplan", "Load Management": "Lastmanagement",
40+
"Peak & Load Management": "Spitzen- & Lastmanagement",
41+
"SOC Zone Configuration": "SOC-Zonen Konfiguration",
42+
"Charging Settings": "Ladeeinstellungen", "Lifetime EV Statistics": "EV Gesamtstatistik",
43+
"Cost Tracking": "Kostenübersicht", "This Year": "Dieses Jahr",
44+
"Energy Costs": "Energiekosten", "Energy Savings": "Energieeinsparungen",
45+
"EV Charging Economics": "EV-Ladekosten", "Return on Investment": "Kapitalrendite",
46+
"Demand Charge": "Leistungspreis", "Tariff Rates": "Tarifpreise",
47+
"System Health": "Systemzustand", "Today": "Heute", "This Month": "Diesen Monat",
48+
},
49+
"fr": {
50+
"EV Charging": "Charge VE", "Surplus Control": "Contrôle surplus",
51+
"Battery Management": "Gestion batterie", "Heat Pump & Hot Water": "Pompe à chaleur",
52+
"Solar & Power": "Solaire & puissance", "Tariff & Pricing": "Tarifs & prix",
53+
"Today's Schedule": "Planning du jour", "Load Management": "Gestion de charge",
54+
"Peak & Load Management": "Gestion pointe & charge",
55+
"SOC Zone Configuration": "Configuration zones SOC",
56+
"Charging Settings": "Paramètres de charge", "Lifetime EV Statistics": "Statistiques VE",
57+
"Cost Tracking": "Suivi des coûts", "This Year": "Cette année",
58+
"Energy Costs": "Coûts énergie", "Energy Savings": "Économies",
59+
"System Health": "Santé système", "Today": "Aujourd'hui", "This Month": "Ce mois",
60+
},
61+
"es": {
62+
"EV Charging": "Carga VE", "Surplus Control": "Control excedente",
63+
"Battery Management": "Gestión batería", "Solar & Power": "Solar y potencia",
64+
"Tariff & Pricing": "Tarifas y precios", "Load Management": "Gestión de carga",
65+
"SOC Zone Configuration": "Configuración zonas SOC",
66+
"Charging Settings": "Ajustes de carga", "Cost Tracking": "Seguimiento costes",
67+
"System Health": "Salud sistema", "Today": "Hoy", "This Month": "Este mes",
68+
"This Year": "Este año",
69+
},
70+
"it": {
71+
"EV Charging": "Carica VE", "Surplus Control": "Controllo eccedenza",
72+
"Battery Management": "Gestione batteria", "Solar & Power": "Solare e potenza",
73+
"Tariff & Pricing": "Tariffe e prezzi", "Load Management": "Gestione carico",
74+
"SOC Zone Configuration": "Configurazione zone SOC",
75+
"Cost Tracking": "Monitoraggio costi", "System Health": "Salute sistema",
76+
"Today": "Oggi", "This Month": "Questo mese", "This Year": "Quest'anno",
77+
},
78+
"nl": {
79+
"EV Charging": "EV laden", "Surplus Control": "Overschotbeheer",
80+
"Battery Management": "Batterijbeheer", "Solar & Power": "Zon & vermogen",
81+
"Tariff & Pricing": "Tarieven & prijzen", "Load Management": "Lastbeheer",
82+
"SOC Zone Configuration": "SOC-zone configuratie",
83+
"Cost Tracking": "Kostenoverzicht", "System Health": "Systeemstatus",
84+
"Today": "Vandaag", "This Month": "Deze maand", "This Year": "Dit jaar",
85+
},
86+
}
87+
88+
def _translate_dashboard(self, config: dict) -> dict:
89+
"""Translate dashboard section titles to user's HA language (#60)."""
90+
lang = self.hass.config.language
91+
translations = self._DASHBOARD_TRANSLATIONS.get(lang)
92+
if not translations:
93+
return config # English or unsupported — keep as-is
94+
95+
def _walk(obj):
96+
if isinstance(obj, dict):
97+
for key in ("title", "subtitle", "primary"):
98+
if key in obj and isinstance(obj[key], str) and obj[key] in translations:
99+
obj[key] = translations[obj[key]]
100+
for v in obj.values():
101+
_walk(v)
102+
elif isinstance(obj, list):
103+
for item in obj:
104+
_walk(item)
105+
106+
_walk(config)
107+
_LOGGER.info("Dashboard translated to '%s' (%d substitutions available)", lang, len(translations))
108+
return config
109+
33110
async def _load_comprehensive_dashboard_template(self) -> Optional[Dict[str, Any]]:
34111
"""Load the comprehensive dashboard template from YAML file."""
35112
try:
@@ -74,6 +151,8 @@ async def generate_dashboard(
74151
template = await self._load_comprehensive_dashboard_template()
75152

76153
if template and "views" in template:
154+
# Translate section titles to user's language (#60)
155+
template = self._translate_dashboard(template)
77156
_LOGGER.info("Using comprehensive dashboard template with %d views", len(template["views"]))
78157

79158
# Find and update views with dynamic content

0 commit comments

Comments
 (0)