Skip to content

Commit

Permalink
support localization for grid usage in display
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen committed Nov 11, 2024
1 parent 4f6f0fd commit d9177da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/Display_Graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions include/I18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/I18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -88,6 +89,14 @@ void I18nClass::readDisplayStrings(
power_kw = displayData["power_kw"].as<String>();
}

if (displayData["meter_power_w"].as<String>() != "null") {
meter_power_w = displayData["meter_power_w"].as<String>();
}

if (displayData["meter_power_kw"].as<String>() != "null") {
meter_power_kw = displayData["meter_power_kw"].as<String>();
}

if (displayData["yield_today_wh"].as<String>() != "null") {
yield_today_wh = displayData["yield_today_wh"].as<String>();
}
Expand Down

0 comments on commit d9177da

Please sign in to comment.