From d9177dad34151ac6353c4bee8360f623278e6c55 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Mon, 11 Nov 2024 22:15:10 +0100 Subject: [PATCH] support localization for grid usage in display --- include/Display_Graphic.h | 2 ++ include/I18n.h | 1 + src/Display_Graphic.cpp | 8 ++++++-- src/I18n.cpp | 9 +++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/Display_Graphic.h b/include/Display_Graphic.h index 2f3287ca7..ab47836d8 100644 --- a/include/Display_Graphic.h +++ b/include/Display_Graphic.h @@ -80,6 +80,8 @@ class DisplayGraphicClass { String _i18n_date_format; String _i18n_current_power_kw; String _i18n_current_power_w; + String _i18n_meter_power_w; + String _i18n_meter_power_kw; String _i18n_yield_total_mwh; String _i18n_yield_total_kwh; }; diff --git a/include/I18n.h b/include/I18n.h index 7187184dd..04dcb8433 100644 --- a/include/I18n.h +++ b/include/I18n.h @@ -22,6 +22,7 @@ class I18nClass { String& date_format, String& offline, String& power_w, String& power_kw, + String& meter_power_w, String& meter_power_kw, String& yield_today_wh, String& yield_today_kwh, String& yield_total_kwh, String& yield_total_mwh); diff --git a/src/Display_Graphic.cpp b/src/Display_Graphic.cpp index 28f8222d9..ce845cec7 100644 --- a/src/Display_Graphic.cpp +++ b/src/Display_Graphic.cpp @@ -179,6 +179,8 @@ void DisplayGraphicClass::setLocale(const String& locale) _i18n_offline = i18n_offline[idx]; _i18n_current_power_w = i18n_current_power_w[idx]; _i18n_current_power_kw = i18n_current_power_kw[idx]; + _i18n_meter_power_w = i18n_meter_power_w[idx]; + _i18n_meter_power_kw = i18n_meter_power_kw[idx]; _i18n_yield_today_wh = i18n_yield_today_wh[idx]; _i18n_yield_today_kwh = i18n_yield_today_kwh[idx]; _i18n_yield_total_kwh = i18n_yield_total_kwh[idx]; @@ -189,6 +191,8 @@ void DisplayGraphicClass::setLocale(const String& locale) _i18n_offline, _i18n_current_power_w, _i18n_current_power_kw, + _i18n_meter_power_w, + _i18n_meter_power_kw, _i18n_yield_today_wh, _i18n_yield_today_kwh, _i18n_yield_total_kwh, @@ -315,9 +319,9 @@ void DisplayGraphicClass::loop() auto acPower = PowerMeter.getPowerTotal(); if (acPower > 999) { - snprintf(_fmtText, sizeof(_fmtText), i18n_meter_power_kw[_display_language], (acPower / 1000)); + snprintf(_fmtText, sizeof(_fmtText), _i18n_meter_power_kw.c_str(), (acPower / 1000)); } else { - snprintf(_fmtText, sizeof(_fmtText), i18n_meter_power_w[_display_language], acPower); + snprintf(_fmtText, sizeof(_fmtText), _i18n_meter_power_w.c_str(), acPower); } printText(_fmtText, 2); diff --git a/src/I18n.cpp b/src/I18n.cpp index 60bbf4237..b8d48e76f 100644 --- a/src/I18n.cpp +++ b/src/I18n.cpp @@ -43,6 +43,7 @@ void I18nClass::readDisplayStrings( String& date_format, String& offline, String& power_w, String& power_kw, + String& meter_power_w, String& meter_power_kw, String& yield_today_wh, String& yield_today_kwh, String& yield_total_kwh, String& yield_total_mwh) { @@ -88,6 +89,14 @@ void I18nClass::readDisplayStrings( power_kw = displayData["power_kw"].as(); } + if (displayData["meter_power_w"].as() != "null") { + meter_power_w = displayData["meter_power_w"].as(); + } + + if (displayData["meter_power_kw"].as() != "null") { + meter_power_kw = displayData["meter_power_kw"].as(); + } + if (displayData["yield_today_wh"].as() != "null") { yield_today_wh = displayData["yield_today_wh"].as(); }