feat: User-Interface I18n System (#728)

## Summary

**What is the goal of this PR?**
This PR introduces Internationalization (i18n) support, enabling users
to switch the UI language dynamically.

**What changes are included?**
- Core Logic: Added I18n class (`lib/I18n/I18n.h/cpp`) to manage
language state and string retrieval.

- Data Structures:

- `lib/I18n/I18nStrings.h/cpp`: Static string arrays for each supported
language.
  - `lib/I18n/I18nKeys.h`: Enum definitions for type-safe string access.
  - `lib/I18n/translations.csv`: single source of truth. 

- Documentation: Added `docs/i18n.md` detailing the workflow for
developers and translators.

- New Settings activity:
`src/activities/settings/LanguageSelectActivity.h/cpp`

## Additional Context

This implementation (building on concepts from #505) prioritizes
performance and memory efficiency.

The core approach is to store all localized strings for each language in
dedicated arrays and access them via enums. This provides O(1) access
with zero runtime overhead, and avoids the heap allocations, hashing,
and collision handling required by `std::map` or `std::unordered_map`.

The main trade-off is that enums and string arrays must remain perfectly
synchronized—any mismatch would result in incorrect strings being
displayed in the UI.

To eliminate this risk, I added a Python script that automatically
generates `I18nStrings.h/.cpp` and `I18nKeys.h` from a CSV file, which
will serve as the single source of truth for all translations. The full
design and workflow are documented in `docs/i18n.md`.

### Next Steps

- [x] Python script `generate_i18n.py` to auto-generate C++ files from
CSV
- [x] Populate translations.csv with initial translations.

Currently available translations: English, Español, Français, Deutsch,
Čeština, Português (Brasil), Русский, Svenska.
Thanks, community!

**Status:** EDIT: ready to be merged.

As a proof of concept, the SPANISH strings currently mirror the English
ones, but are fully uppercased.

---

### AI Usage

Did you use AI tools to help write this code? _**< PARTIALLY >**_
I used AI for the black work of replacing strings with I18n references
across the project, and for generating the documentation. EDIT: also
some help with merging changes from master.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: yeyeto2788 <juanernestobiondi@gmail.com>
This commit is contained in:
Uri Tauber
2026-02-16 15:28:42 +02:00
committed by GitHub
parent 3d47c081f2
commit 7ba5978848
52 changed files with 4516 additions and 379 deletions

View File

@@ -1,6 +1,7 @@
#include "ButtonRemapActivity.h"
#include <GfxRenderer.h>
#include <I18n.h>
#include "CrossPointSettings.h"
#include "MappedInputManager.h"
@@ -106,8 +107,8 @@ void ButtonRemapActivity::render(Activity::RenderLock&&) {
return "-";
};
renderer.drawCenteredText(UI_12_FONT_ID, 15, "Remap Front Buttons", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 40, "Press a front button for each role");
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_REMAP_FRONT_BUTTONS), true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 40, tr(STR_REMAP_PROMPT));
for (uint8_t i = 0; i < kRoleCount; i++) {
const int y = 70 + i * 30;
@@ -122,7 +123,7 @@ void ButtonRemapActivity::render(Activity::RenderLock&&) {
renderer.drawText(UI_10_FONT_ID, 20, y, roleName, !isSelected);
// Show currently assigned hardware button (or unassigned).
const char* assigned = (tempMapping[i] == kUnassigned) ? "Unassigned" : getHardwareName(tempMapping[i]);
const char* assigned = (tempMapping[i] == kUnassigned) ? tr(STR_UNASSIGNED) : getHardwareName(tempMapping[i]);
const auto width = renderer.getTextWidth(UI_10_FONT_ID, assigned);
renderer.drawText(UI_10_FONT_ID, pageWidth - 20 - width, y, assigned, !isSelected);
}
@@ -133,8 +134,8 @@ void ButtonRemapActivity::render(Activity::RenderLock&&) {
}
// Provide side button actions at the bottom of the screen (split across two lines).
renderer.drawCenteredText(SMALL_FONT_ID, 250, "Side button Up: Reset to default layout", true);
renderer.drawCenteredText(SMALL_FONT_ID, 280, "Side button Down: Cancel remapping", true);
renderer.drawCenteredText(SMALL_FONT_ID, 250, tr(STR_REMAP_RESET_HINT), true);
renderer.drawCenteredText(SMALL_FONT_ID, 280, tr(STR_REMAP_CANCEL_HINT), true);
// Live preview of logical labels under front buttons.
// This mirrors the on-device front button order: Back, Confirm, Left, Right.
@@ -157,7 +158,7 @@ bool ButtonRemapActivity::validateUnassigned(const uint8_t pressedButton) {
// Block reusing a hardware button already assigned to another role.
for (uint8_t i = 0; i < kRoleCount; i++) {
if (tempMapping[i] == pressedButton && i != currentStep) {
errorMessage = "Already assigned";
errorMessage = tr(STR_ALREADY_ASSIGNED);
errorUntil = millis() + kErrorDisplayMs;
return false;
}
@@ -168,27 +169,27 @@ bool ButtonRemapActivity::validateUnassigned(const uint8_t pressedButton) {
const char* ButtonRemapActivity::getRoleName(const uint8_t roleIndex) const {
switch (roleIndex) {
case 0:
return "Back";
return tr(STR_BACK);
case 1:
return "Confirm";
return tr(STR_CONFIRM);
case 2:
return "Left";
return tr(STR_DIR_LEFT);
case 3:
default:
return "Right";
return tr(STR_DIR_RIGHT);
}
}
const char* ButtonRemapActivity::getHardwareName(const uint8_t buttonIndex) const {
switch (buttonIndex) {
case CrossPointSettings::FRONT_HW_BACK:
return "Back (1st button)";
return tr(STR_HW_BACK_LABEL);
case CrossPointSettings::FRONT_HW_CONFIRM:
return "Confirm (2nd button)";
return tr(STR_HW_CONFIRM_LABEL);
case CrossPointSettings::FRONT_HW_LEFT:
return "Left (3rd button)";
return tr(STR_HW_LEFT_LABEL);
case CrossPointSettings::FRONT_HW_RIGHT:
return "Right (4th button)";
return tr(STR_HW_RIGHT_LABEL);
default:
return "Unknown";
}

View File

@@ -1,6 +1,7 @@
#include "CalibreSettingsActivity.h"
#include <GfxRenderer.h>
#include <I18n.h>
#include <cstring>
@@ -12,7 +13,7 @@
namespace {
constexpr int MENU_ITEMS = 3;
const char* menuNames[MENU_ITEMS] = {"OPDS Server URL", "Username", "Password"};
const StrId menuNames[MENU_ITEMS] = {StrId::STR_CALIBRE_WEB_URL, StrId::STR_USERNAME, StrId::STR_PASSWORD};
} // namespace
void CalibreSettingsActivity::onEnter() {
@@ -57,7 +58,7 @@ void CalibreSettingsActivity::handleSelection() {
// OPDS Server URL
exitActivity();
enterNewActivity(new KeyboardEntryActivity(
renderer, mappedInput, "OPDS Server URL", SETTINGS.opdsServerUrl, 10,
renderer, mappedInput, tr(STR_CALIBRE_WEB_URL), SETTINGS.opdsServerUrl, 10,
127, // maxLength
false, // not password
[this](const std::string& url) {
@@ -75,7 +76,7 @@ void CalibreSettingsActivity::handleSelection() {
// Username
exitActivity();
enterNewActivity(new KeyboardEntryActivity(
renderer, mappedInput, "Username", SETTINGS.opdsUsername, 10,
renderer, mappedInput, tr(STR_USERNAME), SETTINGS.opdsUsername, 10,
63, // maxLength
false, // not password
[this](const std::string& username) {
@@ -93,7 +94,7 @@ void CalibreSettingsActivity::handleSelection() {
// Password
exitActivity();
enterNewActivity(new KeyboardEntryActivity(
renderer, mappedInput, "Password", SETTINGS.opdsPassword, 10,
renderer, mappedInput, tr(STR_PASSWORD), SETTINGS.opdsPassword, 10,
63, // maxLength
false, // not password mode
[this](const std::string& password) {
@@ -116,10 +117,10 @@ void CalibreSettingsActivity::render(Activity::RenderLock&&) {
const auto pageWidth = renderer.getScreenWidth();
// Draw header
renderer.drawCenteredText(UI_12_FONT_ID, 15, "OPDS Browser", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_OPDS_BROWSER), true, EpdFontFamily::BOLD);
// Draw info text about Calibre
renderer.drawCenteredText(UI_10_FONT_ID, 40, "For Calibre, add /opds to your URL");
renderer.drawCenteredText(UI_10_FONT_ID, 40, tr(STR_CALIBRE_URL_HINT));
// Draw selection highlight
renderer.fillRect(0, 70 + selectedIndex * 30 - 2, pageWidth - 1, 30);
@@ -129,23 +130,26 @@ void CalibreSettingsActivity::render(Activity::RenderLock&&) {
const int settingY = 70 + i * 30;
const bool isSelected = (i == selectedIndex);
renderer.drawText(UI_10_FONT_ID, 20, settingY, menuNames[i], !isSelected);
renderer.drawText(UI_10_FONT_ID, 20, settingY, I18N.get(menuNames[i]), !isSelected);
// Draw status for each setting
const char* status = "[Not Set]";
std::string status = std::string("[") + tr(STR_NOT_SET) + "]";
if (i == 0) {
status = (strlen(SETTINGS.opdsServerUrl) > 0) ? "[Set]" : "[Not Set]";
status = (strlen(SETTINGS.opdsServerUrl) > 0) ? std::string("[") + tr(STR_SET) + "]"
: std::string("[") + tr(STR_NOT_SET) + "]";
} else if (i == 1) {
status = (strlen(SETTINGS.opdsUsername) > 0) ? "[Set]" : "[Not Set]";
status = (strlen(SETTINGS.opdsUsername) > 0) ? std::string("[") + tr(STR_SET) + "]"
: std::string("[") + tr(STR_NOT_SET) + "]";
} else if (i == 2) {
status = (strlen(SETTINGS.opdsPassword) > 0) ? "[Set]" : "[Not Set]";
status = (strlen(SETTINGS.opdsPassword) > 0) ? std::string("[") + tr(STR_SET) + "]"
: std::string("[") + tr(STR_NOT_SET) + "]";
}
const auto width = renderer.getTextWidth(UI_10_FONT_ID, status);
renderer.drawText(UI_10_FONT_ID, pageWidth - 20 - width, settingY, status, !isSelected);
const auto width = renderer.getTextWidth(UI_10_FONT_ID, status.c_str());
renderer.drawText(UI_10_FONT_ID, pageWidth - 20 - width, settingY, status.c_str(), !isSelected);
}
// Draw button hints
const auto labels = mappedInput.mapLabels("« Back", "Select", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();

View File

@@ -2,6 +2,7 @@
#include <GfxRenderer.h>
#include <HalStorage.h>
#include <I18n.h>
#include <Logging.h>
#include "MappedInputManager.h"
@@ -21,46 +22,47 @@ void ClearCacheActivity::render(Activity::RenderLock&&) {
const auto pageHeight = renderer.getScreenHeight();
renderer.clearScreen();
renderer.drawCenteredText(UI_12_FONT_ID, 15, "Clear Cache", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_CLEAR_READING_CACHE), true, EpdFontFamily::BOLD);
if (state == WARNING) {
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 60, "This will clear all cached book data.", true);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 30, "All reading progress will be lost!", true,
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 60, tr(STR_CLEAR_CACHE_WARNING_1), true);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 30, tr(STR_CLEAR_CACHE_WARNING_2), true,
EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 10, "Books will need to be re-indexed", true);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 30, "when opened again.", true);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 10, tr(STR_CLEAR_CACHE_WARNING_3), true);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 30, tr(STR_CLEAR_CACHE_WARNING_4), true);
const auto labels = mappedInput.mapLabels("« Cancel", "Clear", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_CANCEL), tr(STR_CLEAR_BUTTON), "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
return;
}
if (state == CLEARING) {
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, "Clearing cache...", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, tr(STR_CLEARING_CACHE), true, EpdFontFamily::BOLD);
renderer.displayBuffer();
return;
}
if (state == SUCCESS) {
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 20, "Cache Cleared", true, EpdFontFamily::BOLD);
String resultText = String(clearedCount) + " items removed";
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 20, tr(STR_CACHE_CLEARED), true, EpdFontFamily::BOLD);
std::string resultText = std::to_string(clearedCount) + " " + std::string(tr(STR_ITEMS_REMOVED));
if (failedCount > 0) {
resultText += ", " + String(failedCount) + " failed";
resultText += ", " + std::to_string(failedCount) + " " + std::string(tr(STR_FAILED_LOWER));
}
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 10, resultText.c_str());
const auto labels = mappedInput.mapLabels("« Back", "", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
return;
}
if (state == FAILED) {
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 20, "Failed to clear cache", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 10, "Check serial output for details");
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 20, tr(STR_CLEAR_CACHE_FAILED), true,
EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 10, tr(STR_CHECK_SERIAL_OUTPUT));
const auto labels = mappedInput.mapLabels("« Back", "", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
return;

View File

@@ -1,6 +1,7 @@
#include "KOReaderAuthActivity.h"
#include <GfxRenderer.h>
#include <I18n.h>
#include <WiFi.h>
#include "KOReaderCredentialStore.h"
@@ -17,7 +18,7 @@ void KOReaderAuthActivity::onWifiSelectionComplete(const bool success) {
{
RenderLock lock(*this);
state = FAILED;
errorMessage = "WiFi connection failed";
errorMessage = tr(STR_WIFI_CONN_FAILED);
}
requestUpdate();
return;
@@ -26,7 +27,7 @@ void KOReaderAuthActivity::onWifiSelectionComplete(const bool success) {
{
RenderLock lock(*this);
state = AUTHENTICATING;
statusMessage = "Authenticating...";
statusMessage = tr(STR_AUTHENTICATING);
}
requestUpdate();
@@ -40,7 +41,7 @@ void KOReaderAuthActivity::performAuthentication() {
RenderLock lock(*this);
if (result == KOReaderSyncClient::OK) {
state = SUCCESS;
statusMessage = "Successfully authenticated!";
statusMessage = tr(STR_AUTH_SUCCESS);
} else {
state = FAILED;
errorMessage = KOReaderSyncClient::errorString(result);
@@ -58,7 +59,7 @@ void KOReaderAuthActivity::onEnter() {
// Check if already connected
if (WiFi.status() == WL_CONNECTED) {
state = AUTHENTICATING;
statusMessage = "Authenticating...";
statusMessage = tr(STR_AUTHENTICATING);
requestUpdate();
// Perform authentication in a separate task
@@ -89,7 +90,7 @@ void KOReaderAuthActivity::onExit() {
void KOReaderAuthActivity::render(Activity::RenderLock&&) {
renderer.clearScreen();
renderer.drawCenteredText(UI_12_FONT_ID, 15, "KOReader Auth", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_KOREADER_AUTH), true, EpdFontFamily::BOLD);
if (state == AUTHENTICATING) {
renderer.drawCenteredText(UI_10_FONT_ID, 300, statusMessage.c_str(), true, EpdFontFamily::BOLD);
@@ -98,20 +99,20 @@ void KOReaderAuthActivity::render(Activity::RenderLock&&) {
}
if (state == SUCCESS) {
renderer.drawCenteredText(UI_10_FONT_ID, 280, "Success!", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 320, "KOReader sync is ready to use");
renderer.drawCenteredText(UI_10_FONT_ID, 280, tr(STR_AUTH_SUCCESS), true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 320, tr(STR_SYNC_READY));
const auto labels = mappedInput.mapLabels("Done", "", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_DONE), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
return;
}
if (state == FAILED) {
renderer.drawCenteredText(UI_10_FONT_ID, 280, "Authentication Failed", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 280, tr(STR_AUTH_FAILED), true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 320, errorMessage.c_str());
const auto labels = mappedInput.mapLabels("Back", "", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
return;

View File

@@ -1,6 +1,7 @@
#include "KOReaderSettingsActivity.h"
#include <GfxRenderer.h>
#include <I18n.h>
#include <cstring>
@@ -13,7 +14,8 @@
namespace {
constexpr int MENU_ITEMS = 5;
const char* menuNames[MENU_ITEMS] = {"Username", "Password", "Sync Server URL", "Document Matching", "Authenticate"};
const StrId menuNames[MENU_ITEMS] = {StrId::STR_USERNAME, StrId::STR_PASSWORD, StrId::STR_SYNC_SERVER_URL,
StrId::STR_DOCUMENT_MATCHING, StrId::STR_AUTHENTICATE};
} // namespace
void KOReaderSettingsActivity::onEnter() {
@@ -58,7 +60,7 @@ void KOReaderSettingsActivity::handleSelection() {
// Username
exitActivity();
enterNewActivity(new KeyboardEntryActivity(
renderer, mappedInput, "KOReader Username", KOREADER_STORE.getUsername(), 10,
renderer, mappedInput, tr(STR_KOREADER_USERNAME), KOREADER_STORE.getUsername(), 10,
64, // maxLength
false, // not password
[this](const std::string& username) {
@@ -75,7 +77,7 @@ void KOReaderSettingsActivity::handleSelection() {
// Password
exitActivity();
enterNewActivity(new KeyboardEntryActivity(
renderer, mappedInput, "KOReader Password", KOREADER_STORE.getPassword(), 10,
renderer, mappedInput, tr(STR_KOREADER_PASSWORD), KOREADER_STORE.getPassword(), 10,
64, // maxLength
false, // show characters
[this](const std::string& password) {
@@ -94,7 +96,7 @@ void KOReaderSettingsActivity::handleSelection() {
const std::string prefillUrl = currentUrl.empty() ? "https://" : currentUrl;
exitActivity();
enterNewActivity(new KeyboardEntryActivity(
renderer, mappedInput, "Sync Server URL", prefillUrl, 10,
renderer, mappedInput, tr(STR_SYNC_SERVER_URL), prefillUrl, 10,
128, // maxLength - URLs can be long
false, // not password
[this](const std::string& url) {
@@ -137,7 +139,7 @@ void KOReaderSettingsActivity::render(Activity::RenderLock&&) {
const auto pageWidth = renderer.getScreenWidth();
// Draw header
renderer.drawCenteredText(UI_12_FONT_ID, 15, "KOReader Sync", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_KOREADER_SYNC), true, EpdFontFamily::BOLD);
// Draw selection highlight
renderer.fillRect(0, 60 + selectedIndex * 30 - 2, pageWidth - 1, 30);
@@ -147,28 +149,31 @@ void KOReaderSettingsActivity::render(Activity::RenderLock&&) {
const int settingY = 60 + i * 30;
const bool isSelected = (i == selectedIndex);
renderer.drawText(UI_10_FONT_ID, 20, settingY, menuNames[i], !isSelected);
renderer.drawText(UI_10_FONT_ID, 20, settingY, I18N.get(menuNames[i]), !isSelected);
// Draw status for each item
const char* status = "";
std::string status = "";
if (i == 0) {
status = KOREADER_STORE.getUsername().empty() ? "[Not Set]" : "[Set]";
status = std::string("[") + (KOREADER_STORE.getUsername().empty() ? tr(STR_NOT_SET) : tr(STR_SET)) + "]";
} else if (i == 1) {
status = KOREADER_STORE.getPassword().empty() ? "[Not Set]" : "[Set]";
status = std::string("[") + (KOREADER_STORE.getPassword().empty() ? tr(STR_NOT_SET) : tr(STR_SET)) + "]";
} else if (i == 2) {
status = KOREADER_STORE.getServerUrl().empty() ? "[Default]" : "[Custom]";
status =
std::string("[") + (KOREADER_STORE.getServerUrl().empty() ? tr(STR_DEFAULT_VALUE) : tr(STR_CUSTOM)) + "]";
} else if (i == 3) {
status = KOREADER_STORE.getMatchMethod() == DocumentMatchMethod::FILENAME ? "[Filename]" : "[Binary]";
status = std::string("[") +
(KOREADER_STORE.getMatchMethod() == DocumentMatchMethod::FILENAME ? tr(STR_FILENAME) : tr(STR_BINARY)) +
"]";
} else if (i == 4) {
status = KOREADER_STORE.hasCredentials() ? "" : "[Set credentials first]";
status = KOREADER_STORE.hasCredentials() ? "" : std::string("[") + tr(STR_SET_CREDENTIALS_FIRST) + "]";
}
const auto width = renderer.getTextWidth(UI_10_FONT_ID, status);
renderer.drawText(UI_10_FONT_ID, pageWidth - 20 - width, settingY, status, !isSelected);
const auto width = renderer.getTextWidth(UI_10_FONT_ID, status.c_str());
renderer.drawText(UI_10_FONT_ID, pageWidth - 20 - width, settingY, status.c_str(), !isSelected);
}
// Draw button hints
const auto labels = mappedInput.mapLabels("« Back", "Select", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();

View File

@@ -0,0 +1,94 @@
#include "LanguageSelectActivity.h"
#include <GfxRenderer.h>
#include <I18n.h>
#include "MappedInputManager.h"
#include "fontIds.h"
void LanguageSelectActivity::onEnter() {
Activity::onEnter();
totalItems = getLanguageCount();
// Set current selection based on current language
selectedIndex = static_cast<int>(I18N.getLanguage());
requestUpdate();
}
void LanguageSelectActivity::onExit() { Activity::onExit(); }
void LanguageSelectActivity::loop() {
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
onBack();
return;
}
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
handleSelection();
return;
}
if (mappedInput.wasPressed(MappedInputManager::Button::Up) ||
mappedInput.wasPressed(MappedInputManager::Button::Left)) {
selectedIndex = (selectedIndex + totalItems - 1) % totalItems;
requestUpdate();
} else if (mappedInput.wasPressed(MappedInputManager::Button::Down) ||
mappedInput.wasPressed(MappedInputManager::Button::Right)) {
selectedIndex = (selectedIndex + 1) % totalItems;
requestUpdate();
}
}
void LanguageSelectActivity::handleSelection() {
{
RenderLock lock(*this);
I18N.setLanguage(static_cast<Language>(selectedIndex));
}
// Return to previous page
onBack();
}
void LanguageSelectActivity::render(Activity::RenderLock&&) {
renderer.clearScreen();
const auto pageWidth = renderer.getScreenWidth();
constexpr int rowHeight = 30;
// Title
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_LANGUAGE), true, EpdFontFamily::BOLD);
// Current language marker
const int currentLang = static_cast<int>(I18N.getLanguage());
// Draw options
for (int i = 0; i < totalItems; i++) {
const int itemY = 60 + i * rowHeight;
const bool isSelected = (i == selectedIndex);
const bool isCurrent = (i == currentLang);
// Draw selection highlight
if (isSelected) {
renderer.fillRect(0, itemY - 2, pageWidth - 1, rowHeight);
}
// Draw language name - get it from i18n system
const char* langName = I18N.getLanguageName(static_cast<Language>(i));
renderer.drawText(UI_10_FONT_ID, 20, itemY, langName, !isSelected);
// Draw current selection marker
if (isCurrent) {
const char* marker = tr(STR_ON_MARKER);
const auto width = renderer.getTextWidth(UI_10_FONT_ID, marker);
renderer.drawText(UI_10_FONT_ID, pageWidth - 20 - width, itemY, marker, !isSelected);
}
}
// Button hints
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include <GfxRenderer.h>
#include <I18n.h>
#include <functional>
#include "../ActivityWithSubactivity.h"
#include "components/UITheme.h"
class MappedInputManager;
/**
* Activity for selecting UI language
*/
class LanguageSelectActivity final : public Activity {
public:
explicit LanguageSelectActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void()>& onBack)
: Activity("LanguageSelect", renderer, mappedInput), onBack(onBack) {}
void onEnter() override;
void onExit() override;
void loop() override;
void render(Activity::RenderLock&&) override;
private:
void handleSelection();
std::function<void()> onBack;
int selectedIndex = 0;
int totalItems = 0;
};

View File

@@ -1,6 +1,7 @@
#include "OtaUpdateActivity.h"
#include <GfxRenderer.h>
#include <I18n.h>
#include <WiFi.h>
#include "MappedInputManager.h"
@@ -97,27 +98,27 @@ void OtaUpdateActivity::render(Activity::RenderLock&&) {
const auto pageWidth = renderer.getScreenWidth();
renderer.clearScreen();
renderer.drawCenteredText(UI_12_FONT_ID, 15, "Update", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_UPDATE), true, EpdFontFamily::BOLD);
if (state == CHECKING_FOR_UPDATE) {
renderer.drawCenteredText(UI_10_FONT_ID, 300, "Checking for update...", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 300, tr(STR_CHECKING_UPDATE), true, EpdFontFamily::BOLD);
renderer.displayBuffer();
return;
}
if (state == WAITING_CONFIRMATION) {
renderer.drawCenteredText(UI_10_FONT_ID, 200, "New update available!", true, EpdFontFamily::BOLD);
renderer.drawText(UI_10_FONT_ID, 20, 250, "Current Version: " CROSSPOINT_VERSION);
renderer.drawText(UI_10_FONT_ID, 20, 270, ("New Version: " + updater.getLatestVersion()).c_str());
renderer.drawCenteredText(UI_10_FONT_ID, 200, tr(STR_NEW_UPDATE), true, EpdFontFamily::BOLD);
renderer.drawText(UI_10_FONT_ID, 20, 250, (std::string(tr(STR_CURRENT_VERSION)) + CROSSPOINT_VERSION).c_str());
renderer.drawText(UI_10_FONT_ID, 20, 270, (std::string(tr(STR_NEW_VERSION)) + updater.getLatestVersion()).c_str());
const auto labels = mappedInput.mapLabels("Cancel", "Update", "", "");
const auto labels = mappedInput.mapLabels(tr(STR_CANCEL), tr(STR_UPDATE), "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
return;
}
if (state == UPDATE_IN_PROGRESS) {
renderer.drawCenteredText(UI_10_FONT_ID, 310, "Updating...", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 310, tr(STR_UPDATING), true, EpdFontFamily::BOLD);
renderer.drawRect(20, 350, pageWidth - 40, 50);
renderer.fillRect(24, 354, static_cast<int>(updaterProgress * static_cast<float>(pageWidth - 44)), 42);
renderer.drawCenteredText(UI_10_FONT_ID, 420,
@@ -130,20 +131,20 @@ void OtaUpdateActivity::render(Activity::RenderLock&&) {
}
if (state == NO_UPDATE) {
renderer.drawCenteredText(UI_10_FONT_ID, 300, "No update available", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 300, tr(STR_NO_UPDATE), true, EpdFontFamily::BOLD);
renderer.displayBuffer();
return;
}
if (state == FAILED) {
renderer.drawCenteredText(UI_10_FONT_ID, 300, "Update failed", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 300, tr(STR_UPDATE_FAILED), true, EpdFontFamily::BOLD);
renderer.displayBuffer();
return;
}
if (state == FINISHED) {
renderer.drawCenteredText(UI_10_FONT_ID, 300, "Update complete", true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 350, "Press and hold power button to turn back on");
renderer.drawCenteredText(UI_10_FONT_ID, 300, tr(STR_UPDATE_COMPLETE), true, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_10_FONT_ID, 350, tr(STR_POWER_ON_HINT));
renderer.displayBuffer();
state = SHUTTING_DOWN;
return;

View File

@@ -8,6 +8,7 @@
#include "ClearCacheActivity.h"
#include "CrossPointSettings.h"
#include "KOReaderSettingsActivity.h"
#include "LanguageSelectActivity.h"
#include "MappedInputManager.h"
#include "OtaUpdateActivity.h"
#include "SettingsList.h"
@@ -15,7 +16,8 @@
#include "components/UITheme.h"
#include "fontIds.h"
const char* SettingsActivity::categoryNames[categoryCount] = {"Display", "Reader", "Controls", "System"};
const StrId SettingsActivity::categoryNames[categoryCount] = {StrId::STR_CAT_DISPLAY, StrId::STR_CAT_READER,
StrId::STR_CAT_CONTROLS, StrId::STR_CAT_SYSTEM};
void SettingsActivity::onEnter() {
Activity::onEnter();
@@ -27,14 +29,14 @@ void SettingsActivity::onEnter() {
systemSettings.clear();
for (auto& setting : getSettingsList()) {
if (!setting.category) continue;
if (strcmp(setting.category, "Display") == 0) {
if (setting.category == StrId::STR_NONE_OPT) continue;
if (setting.category == StrId::STR_CAT_DISPLAY) {
displaySettings.push_back(std::move(setting));
} else if (strcmp(setting.category, "Reader") == 0) {
} else if (setting.category == StrId::STR_CAT_READER) {
readerSettings.push_back(std::move(setting));
} else if (strcmp(setting.category, "Controls") == 0) {
} else if (setting.category == StrId::STR_CAT_CONTROLS) {
controlsSettings.push_back(std::move(setting));
} else if (strcmp(setting.category, "System") == 0) {
} else if (setting.category == StrId::STR_CAT_SYSTEM) {
systemSettings.push_back(std::move(setting));
}
// Web-only categories (KOReader Sync, OPDS Browser) are skipped for device UI
@@ -42,12 +44,13 @@ void SettingsActivity::onEnter() {
// Append device-only ACTION items
controlsSettings.insert(controlsSettings.begin(),
SettingInfo::Action("Remap Front Buttons", SettingAction::RemapFrontButtons));
systemSettings.push_back(SettingInfo::Action("Network", SettingAction::Network));
systemSettings.push_back(SettingInfo::Action("KOReader Sync", SettingAction::KOReaderSync));
systemSettings.push_back(SettingInfo::Action("OPDS Browser", SettingAction::OPDSBrowser));
systemSettings.push_back(SettingInfo::Action("Clear Cache", SettingAction::ClearCache));
systemSettings.push_back(SettingInfo::Action("Check for updates", SettingAction::CheckForUpdates));
SettingInfo::Action(StrId::STR_REMAP_FRONT_BUTTONS, SettingAction::RemapFrontButtons));
systemSettings.push_back(SettingInfo::Action(StrId::STR_WIFI_NETWORKS, SettingAction::Network));
systemSettings.push_back(SettingInfo::Action(StrId::STR_KOREADER_SYNC, SettingAction::KOReaderSync));
systemSettings.push_back(SettingInfo::Action(StrId::STR_OPDS_BROWSER, SettingAction::OPDSBrowser));
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLEAR_READING_CACHE, SettingAction::ClearCache));
systemSettings.push_back(SettingInfo::Action(StrId::STR_CHECK_UPDATES, SettingAction::CheckForUpdates));
systemSettings.push_back(SettingInfo::Action(StrId::STR_LANGUAGE, SettingAction::Language));
// Reset selection to first category
selectedCategoryIndex = 0;
@@ -193,6 +196,9 @@ void SettingsActivity::toggleCurrentSetting() {
case SettingAction::CheckForUpdates:
enterSubActivity(new OtaUpdateActivity(renderer, mappedInput, onComplete));
break;
case SettingAction::Language:
enterSubActivity(new LanguageSelectActivity(renderer, mappedInput, onComplete));
break;
case SettingAction::None:
// Do nothing
break;
@@ -212,12 +218,12 @@ void SettingsActivity::render(Activity::RenderLock&&) {
auto metrics = UITheme::getInstance().getMetrics();
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, "Settings");
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_SETTINGS_TITLE));
std::vector<TabInfo> tabs;
tabs.reserve(categoryCount);
for (int i = 0; i < categoryCount; i++) {
tabs.push_back({categoryNames[i], selectedCategoryIndex == i});
tabs.push_back({I18N.get(categoryNames[i]), selectedCategoryIndex == i});
}
GUI.drawTabBar(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight}, tabs,
selectedSettingIndex == 0);
@@ -228,18 +234,19 @@ void SettingsActivity::render(Activity::RenderLock&&) {
Rect{0, metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing, pageWidth,
pageHeight - (metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.buttonHintsHeight +
metrics.verticalSpacing * 2)},
settingsCount, selectedSettingIndex - 1, [&settings](int index) { return std::string(settings[index].name); },
nullptr, nullptr,
settingsCount, selectedSettingIndex - 1,
[&settings](int index) { return std::string(I18N.get(settings[index].nameId)); }, nullptr, nullptr,
[&settings](int i) {
const auto& setting = settings[i];
std::string valueText = "";
if (settings[i].type == SettingType::TOGGLE && settings[i].valuePtr != nullptr) {
const bool value = SETTINGS.*(settings[i].valuePtr);
valueText = value ? "ON" : "OFF";
} else if (settings[i].type == SettingType::ENUM && settings[i].valuePtr != nullptr) {
const uint8_t value = SETTINGS.*(settings[i].valuePtr);
valueText = settings[i].enumValues[value];
} else if (settings[i].type == SettingType::VALUE && settings[i].valuePtr != nullptr) {
valueText = std::to_string(SETTINGS.*(settings[i].valuePtr));
if (setting.type == SettingType::TOGGLE && setting.valuePtr != nullptr) {
const bool value = SETTINGS.*(setting.valuePtr);
valueText = value ? tr(STR_STATE_ON) : tr(STR_STATE_OFF);
} else if (setting.type == SettingType::ENUM && setting.valuePtr != nullptr) {
const uint8_t value = SETTINGS.*(setting.valuePtr);
valueText = I18N.get(setting.enumValues[value]);
} else if (setting.type == SettingType::VALUE && setting.valuePtr != nullptr) {
valueText = std::to_string(SETTINGS.*(setting.valuePtr));
}
return valueText;
});
@@ -250,7 +257,7 @@ void SettingsActivity::render(Activity::RenderLock&&) {
metrics.versionTextY, CROSSPOINT_VERSION);
// Draw help text
const auto labels = mappedInput.mapLabels("« Back", "Toggle", "Up", "Down");
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_TOGGLE), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
// Always use standard refresh for settings screen

View File

@@ -1,4 +1,5 @@
#pragma once
#include <I18n.h>
#include <functional>
#include <string>
@@ -19,13 +20,14 @@ enum class SettingAction {
Network,
ClearCache,
CheckForUpdates,
Language,
};
struct SettingInfo {
const char* name;
StrId nameId;
SettingType type;
uint8_t CrossPointSettings::* valuePtr = nullptr;
std::vector<std::string> enumValues;
std::vector<StrId> enumValues;
SettingAction action = SettingAction::None;
struct ValueRange {
@@ -35,8 +37,8 @@ struct SettingInfo {
};
ValueRange valueRange = {};
const char* key = nullptr; // JSON API key (nullptr for ACTION types)
const char* category = nullptr; // Category for web UI grouping
const char* key = nullptr; // JSON API key (nullptr for ACTION types)
StrId category = StrId::STR_NONE_OPT; // Category for web UI grouping
// Direct char[] string fields (for settings stored in CrossPointSettings)
char* stringPtr = nullptr;
@@ -48,10 +50,10 @@ struct SettingInfo {
std::function<std::string()> stringGetter;
std::function<void(const std::string&)> stringSetter;
static SettingInfo Toggle(const char* name, uint8_t CrossPointSettings::* ptr, const char* key = nullptr,
const char* category = nullptr) {
static SettingInfo Toggle(StrId nameId, uint8_t CrossPointSettings::* ptr, const char* key = nullptr,
StrId category = StrId::STR_NONE_OPT) {
SettingInfo s;
s.name = name;
s.nameId = nameId;
s.type = SettingType::TOGGLE;
s.valuePtr = ptr;
s.key = key;
@@ -59,10 +61,10 @@ struct SettingInfo {
return s;
}
static SettingInfo Enum(const char* name, uint8_t CrossPointSettings::* ptr, std::vector<std::string> values,
const char* key = nullptr, const char* category = nullptr) {
static SettingInfo Enum(StrId nameId, uint8_t CrossPointSettings::* ptr, std::vector<StrId> values,
const char* key = nullptr, StrId category = StrId::STR_NONE_OPT) {
SettingInfo s;
s.name = name;
s.nameId = nameId;
s.type = SettingType::ENUM;
s.valuePtr = ptr;
s.enumValues = std::move(values);
@@ -71,18 +73,18 @@ struct SettingInfo {
return s;
}
static SettingInfo Action(const char* name, SettingAction action) {
static SettingInfo Action(StrId nameId, SettingAction action) {
SettingInfo s;
s.name = name;
s.nameId = nameId;
s.type = SettingType::ACTION;
s.action = action;
return s;
}
static SettingInfo Value(const char* name, uint8_t CrossPointSettings::* ptr, const ValueRange valueRange,
const char* key = nullptr, const char* category = nullptr) {
static SettingInfo Value(StrId nameId, uint8_t CrossPointSettings::* ptr, const ValueRange valueRange,
const char* key = nullptr, StrId category = StrId::STR_NONE_OPT) {
SettingInfo s;
s.name = name;
s.nameId = nameId;
s.type = SettingType::VALUE;
s.valuePtr = ptr;
s.valueRange = valueRange;
@@ -91,10 +93,10 @@ struct SettingInfo {
return s;
}
static SettingInfo String(const char* name, char* ptr, size_t maxLen, const char* key = nullptr,
const char* category = nullptr) {
static SettingInfo String(StrId nameId, char* ptr, size_t maxLen, const char* key = nullptr,
StrId category = StrId::STR_NONE_OPT) {
SettingInfo s;
s.name = name;
s.nameId = nameId;
s.type = SettingType::STRING;
s.stringPtr = ptr;
s.stringMaxLen = maxLen;
@@ -103,11 +105,11 @@ struct SettingInfo {
return s;
}
static SettingInfo DynamicEnum(const char* name, std::vector<std::string> values, std::function<uint8_t()> getter,
static SettingInfo DynamicEnum(StrId nameId, std::vector<StrId> values, std::function<uint8_t()> getter,
std::function<void(uint8_t)> setter, const char* key = nullptr,
const char* category = nullptr) {
StrId category = StrId::STR_NONE_OPT) {
SettingInfo s;
s.name = name;
s.nameId = nameId;
s.type = SettingType::ENUM;
s.enumValues = std::move(values);
s.valueGetter = std::move(getter);
@@ -117,11 +119,11 @@ struct SettingInfo {
return s;
}
static SettingInfo DynamicString(const char* name, std::function<std::string()> getter,
static SettingInfo DynamicString(StrId nameId, std::function<std::string()> getter,
std::function<void(const std::string&)> setter, const char* key = nullptr,
const char* category = nullptr) {
StrId category = StrId::STR_NONE_OPT) {
SettingInfo s;
s.name = name;
s.nameId = nameId;
s.type = SettingType::STRING;
s.stringGetter = std::move(getter);
s.stringSetter = std::move(setter);
@@ -148,7 +150,7 @@ class SettingsActivity final : public ActivityWithSubactivity {
const std::function<void()> onGoHome;
static constexpr int categoryCount = 4;
static const char* categoryNames[categoryCount];
static const StrId categoryNames[categoryCount];
void enterCategory(int categoryIndex);
void toggleCurrentSetting();