Skip to content

Commit

Permalink
Refactor i18n usage in ParqetWidget for improved localization
Browse files Browse the repository at this point in the history
Replaced hardcoded strings with the newly implemented `i18n` function, centralizing translation handling and improving maintainability. Updated translation files (en/de) with additional keys for widget configuration options and labels. This ensures consistency and simplifies future localization efforts.
  • Loading branch information
flattermann committed Feb 24, 2025
1 parent 1fff023 commit 50ca42c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
6 changes: 5 additions & 1 deletion firmware/src/core/widget/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ void Widget::setBusy(bool busy) {

bool Widget::isEnabled() {
return m_enabled;
}
}

const char *Widget::i18n(const String &key) {
return I18n::get(key);
}
1 change: 1 addition & 0 deletions firmware/src/core/widget/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Widget {
virtual String getName() = 0;
void setBusy(bool busy);
bool isEnabled();
static const char *i18n(const String &key);

protected:
ScreenManager &m_manager;
Expand Down
18 changes: 9 additions & 9 deletions firmware/src/widgets/parqetwidget/ParqetWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ ParqetWidget::ParqetWidget(ScreenManager &manager, ConfigManager &config) : Widg
Serial.printf("Constructing ParqetWidget, portfolioId=%s\n", m_portfolioId.c_str());
// Load widget specific translations
I18n::loadExtraTranslations(ParqetWidget::getName());
m_config.addConfigBool("ParqetWidget", "pqEnabled", &m_enabled, I18n::get("enable_widget"));
m_config.addConfigString("ParqetWidget", "pqportfoId", &m_portfolioId, 50, I18n::get("parqet.enter_portfolio_id"));
m_config.addConfigComboBox("ParqetWidget", "pqDefMode", &m_defaultMode, m_modes, PARQET_MODE_COUNT, "Default timeframe (you can change timeframes by medium pressing the middle button)", true);
m_config.addConfigBool("ParqetWidget", "pqShowClock", &m_showClock, "Show clock on first screen", true);
m_config.addConfigBool("ParqetWidget", "pqShowTotalScr", &m_showTotalScreen, "Show totals screen", true);
m_config.addConfigBool("ParqetWidget", "pqShowTotalVal", &m_showTotalValue, "Show total portfolio value", true);
m_config.addConfigBool("ParqetWidget", "pqEnabled", &m_enabled, i18n("enable_widget"));
m_config.addConfigString("ParqetWidget", "pqportfoId", &m_portfolioId, 50, i18n("pq.cnf.portfolio_id"));
m_config.addConfigComboBox("ParqetWidget", "pqDefMode", &m_defaultMode, m_modes, PARQET_MODE_COUNT, i18n("pq.cnf.mode"), true);
m_config.addConfigBool("ParqetWidget", "pqShowClock", &m_showClock, i18n("pq.cnf.clock"), true);
m_config.addConfigBool("ParqetWidget", "pqShowTotalScr", &m_showTotalScreen, i18n("pq.cnf.totals"), true);
m_config.addConfigBool("ParqetWidget", "pqShowTotalVal", &m_showTotalValue, i18n("pq.cnf.total_val"), true);
String optPriceVal[] = {"Show current price", "Show current value"};
m_config.addConfigComboBox("ParqetWidget", "pqShowValues", &m_showValues, optPriceVal, 2, "Show price or value for stocks", true);
m_config.addConfigComboBox("ParqetWidget", "pqShowValues", &m_showValues, optPriceVal, 2, i18n("pq.cnf.values"), true);
m_curMode = m_defaultMode;
}

Expand Down Expand Up @@ -207,7 +207,7 @@ void ParqetWidget::updatePortfolio() {
JsonVariant perf = doc["performance"];
ParqetHoldingDataModel h = ParqetHoldingDataModel();
h.setId("total");
h.setName("T O T A L");
h.setName(i18n("pq.total"));
h.setPurchasePrice(perf["purchaseValueForInterval"].as<float>());
h.setPurchaseValue(perf["purchaseValueForInterval"].as<float>());
h.setCurrentPrice(perf["portfolioValue"].as<float>());
Expand Down Expand Up @@ -358,7 +358,7 @@ void ParqetWidget::displayStock(int8_t displayIndex, ParqetHoldingDataModel &sto
m_manager.drawString(stock.getCurrentPrice(2), ScreenCenterX, 58, 26, Align::MiddleCenter);
}
} else {
m_manager.drawString("Portfolio", ScreenCenterX, 58, 26, Align::MiddleCenter);
m_manager.drawString(i18n("pq.portfolio"), ScreenCenterX, 58, 26, Align::MiddleCenter);
}

if (m_showTotalChart && stock.getId() == "total" && m_portfolio.getChartDataCount() >= 7) {
Expand Down
10 changes: 8 additions & 2 deletions i18n/de.parqet.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
parqet.name=Parqet
parqet.enter_portfolio_id=Portfolio ID (muss auf öffentlich stehen!)
pq.portfolio=Portfolio
pq.total=G E S A M T
pq.cnf.portfolio_id=Portfolio-ID (muss auf öffentlich stehen!)
pq.cnf.mode=Standardzeitraum (Zeitraum kann durch mittellanges Drücken des mittleren Buttons geändert werden)
pq.cnf.clock=Uhr auf dem ersten Bildschirm anzeigen
pq.cnf.totals=Gesamtübersicht anzeigen
pq.cnf.total_val=Gesamtwert des Portfolios anzeigen
pq.cnf.values=Preis oder Wert der Aktien anzeigen
10 changes: 8 additions & 2 deletions i18n/en.parqet.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
parqet.name=Parqet
parqet.enter_portfolio_id=Portfolio ID (must be set to public!)
pq.portfolio=Portfolio
pq.total=T O T A L
pq.cnf.portfolio_id=Portfolio ID (must be set to public!)
pq.cnf.mode=Default timeframe (you can change timeframes by medium pressing the middle button)
pq.cnf.clock=Show clock on first screen
pq.cnf.totals=Show totals screen
pq.cnf.total_val=Show total portfolio value
pq.cnf.values=Show price or value for stocks

0 comments on commit 50ca42c

Please sign in to comment.