fix: localize sleep overlay strings, validate TXT cache header, migrate overlay enum

This commit is contained in:
pablohc
2026-03-29 21:55:51 +02:00
parent 389ed7266b
commit 0f1d3ef31d
5 changed files with 102 additions and 18 deletions
+4 -2
View File
@@ -351,6 +351,9 @@ enum class StrId : uint16_t {
STR_OVERLAY_GRAY, STR_OVERLAY_GRAY,
STR_OVERLAY_BLACK, STR_OVERLAY_BLACK,
STR_OVERLAY_OFF, STR_OVERLAY_OFF,
STR_OVERLAY_READING_PROGRESS,
STR_OVERLAY_READING_PROGRESS_NO_TOTAL,
STR_OVERLAY_CHAPTER_PAGE_SUFFIX,
// Sentinel - must be last // Sentinel - must be last
_COUNT _COUNT
}; };
@@ -405,8 +408,7 @@ inline const char* const* getStringArray(Language lang) {
constexpr uint8_t getLanguageCount() { return static_cast<uint8_t>(Language::_COUNT); } constexpr uint8_t getLanguageCount() { return static_cast<uint8_t>(Language::_COUNT); }
// Sorted language indices by code (auto-generated by gen_i18n.py) // Sorted language indices by code (auto-generated by gen_i18n.py)
// Order: English, Беларуская, Català, Čeština, Dansk, Deutsch, Español, Suomi, Français, Italiano, Қазақша, Nederlands, // Order: English, Беларуская, Català, Čeština, Dansk, Deutsch, Español, Suomi, Français, Italiano, Қазақша, Nederlands, Polski, Português (Brasil), Română, Русский, Svenska, Türkçe, Українська
// Polski, Português (Brasil), Română, Русский, Svenska, Türkçe, Українська
constexpr uint8_t SORTED_LANGUAGE_INDICES[] = {0, 11, 9, 4, 15, 3, 1, 14, 2, 12, 18, 16, 13, 5, 8, 6, 7, 17, 10}; constexpr uint8_t SORTED_LANGUAGE_INDICES[] = {0, 11, 9, 4, 15, 3, 1, 14, 2, 12, 18, 16, 13, 5, 8, 6, 7, 17, 10};
static_assert(sizeof(SORTED_LANGUAGE_INDICES) / sizeof(SORTED_LANGUAGE_INDICES[0]) == getLanguageCount(), static_assert(sizeof(SORTED_LANGUAGE_INDICES) / sizeof(SORTED_LANGUAGE_INDICES[0]) == getLanguageCount(),
+61 -4
View File
@@ -137,7 +137,7 @@ const char* const CHARACTER_SETS[] = {
"\xC3" "\xC3"
"\xBA" "\xBA"
"", // Español "", // Español
" !%'()*+,./012345:=?ABCDEFGHIJKLMNOPQRSTUVW[]abcdefghijklmnopqrstuvwxyz|\xC2" " !%'()*+,-./012345:=?ABCDEFGHIJKLMNOPQRSTUVW[]abcdefghijklmnopqrstuvwxyz|\xC2"
"\xAB" "\xAB"
"\xC3" "\xC3"
"\x89" "\x89"
@@ -185,7 +185,7 @@ const char* const CHARACTER_SETS[] = {
"\x80" "\x80"
"\xA6" "\xA6"
"", // Deutsch "", // Deutsch
" !%()*+,./012345:=?ABCDEFGHIJKLMNOPQRSTUVWYZ[]abcdefghijklmnoprstuvwxyz|\xC2" " !%()*+,-./012345:=?ABCDEFGHIJKLMNOPQRSTUVWYZ[]abcdefghijklmnoprstuvwxyz|\xC2"
"\xAB" "\xAB"
"\xC3" "\xC3"
"\x81" "\x81"
@@ -758,7 +758,7 @@ const char* const CHARACTER_SETS[] = {
"\xC3" "\xC3"
"\xBC" "\xBC"
"", // Nederlands "", // Nederlands
" !\"%'()*+,./012345:=?ABCDEFGHIKLMNOPQRSTUVWYZ[]abcdefghiklmnoprstuvwxyz|\xC2" " !\"%'()*+,-./012345:=?ABCDEFGHIKLMNOPQRSTUVWYZ[]abcdefghiklmnoprstuvwxyz|\xC2"
"\xAB" "\xAB"
"\xC3" "\xC3"
"\x87" "\x87"
@@ -781,7 +781,7 @@ const char* const CHARACTER_SETS[] = {
"\xC5" "\xC5"
"\x9F" "\x9F"
"", // Türkçe "", // Türkçe
" !\"%()*+,-./012345:=?ABCDFGHIKLMNOPQRSUW[]abcdefhiklnoprstuvwxyz|\xC2" " !\"%()*+,-./012345:=?ABCDFGHIKLMNOPQRSUW[]abcdefghiklnoprstuvwxyz|\xC2"
"\xAB" "\xAB"
"\xD0" "\xD0"
"\x86" "\x86"
@@ -1214,6 +1214,9 @@ const char* const STRINGS_EN[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_ES[] = { const char* const STRINGS_ES[] = {
@@ -1746,6 +1749,9 @@ const char* const STRINGS_ES[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_FR[] = { const char* const STRINGS_FR[] = {
@@ -2382,6 +2388,9 @@ const char* const STRINGS_FR[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_DE[] = { const char* const STRINGS_DE[] = {
@@ -2826,6 +2835,9 @@ const char* const STRINGS_DE[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_CS[] = { const char* const STRINGS_CS[] = {
@@ -4187,6 +4199,9 @@ const char* const STRINGS_CS[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_PO[] = { const char* const STRINGS_PO[] = {
@@ -4753,6 +4768,9 @@ const char* const STRINGS_PO[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_RU[] = { const char* const STRINGS_RU[] = {
@@ -11975,6 +11993,9 @@ const char* const STRINGS_RU[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_SV[] = { const char* const STRINGS_SV[] = {
@@ -12700,6 +12721,9 @@ const char* const STRINGS_SV[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_RO[] = { const char* const STRINGS_RO[] = {
@@ -13554,6 +13578,9 @@ const char* const STRINGS_RO[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_CA[] = { const char* const STRINGS_CA[] = {
@@ -14138,6 +14165,9 @@ const char* const STRINGS_CA[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_UK[] = { const char* const STRINGS_UK[] = {
@@ -22374,6 +22404,9 @@ const char* const STRINGS_UK[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_BE[] = { const char* const STRINGS_BE[] = {
@@ -29284,6 +29317,9 @@ const char* const STRINGS_BE[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_IT[] = { const char* const STRINGS_IT[] = {
@@ -29622,6 +29658,9 @@ const char* const STRINGS_IT[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_PL[] = { const char* const STRINGS_PL[] = {
@@ -30498,6 +30537,9 @@ const char* const STRINGS_PL[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_FI[] = { const char* const STRINGS_FI[] = {
@@ -31192,6 +31234,9 @@ const char* const STRINGS_FI[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_DA[] = { const char* const STRINGS_DA[] = {
@@ -31684,6 +31729,9 @@ const char* const STRINGS_DA[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_NL[] = { const char* const STRINGS_NL[] = {
@@ -31992,6 +32040,9 @@ const char* const STRINGS_NL[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_TR[] = { const char* const STRINGS_TR[] = {
@@ -33176,6 +33227,9 @@ const char* const STRINGS_TR[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
const char* const STRINGS_KK[] = { const char* const STRINGS_KK[] = {
@@ -40892,6 +40946,9 @@ const char* const STRINGS_KK[] = {
"Gray", "Gray",
"Black", "Black",
"Off", "Off",
"Reading progress: Page %lu/%u - %.0f%%",
"Reading progress: Page %lu",
" - Page %d/%d - %.0f%%",
}; };
} // namespace i18n_strings } // namespace i18n_strings
+3
View File
@@ -295,3 +295,6 @@ STR_OVERLAY_WHITE: "White"
STR_OVERLAY_GRAY: "Gray" STR_OVERLAY_GRAY: "Gray"
STR_OVERLAY_BLACK: "Black" STR_OVERLAY_BLACK: "Black"
STR_OVERLAY_OFF: "Off" STR_OVERLAY_OFF: "Off"
STR_OVERLAY_READING_PROGRESS: "Reading progress: Page %lu/%u - %.0f%%"
STR_OVERLAY_READING_PROGRESS_NO_TOTAL: "Reading progress: Page %lu"
STR_OVERLAY_CHAPTER_PAGE_SUFFIX: " - Page %d/%d - %.0f%%"
+13
View File
@@ -143,6 +143,19 @@ bool JsonSettingsIO::loadSettings(CrossPointSettings& s, const char* json, bool*
applyLegacyStatusBarSettings(s); applyLegacyStatusBarSettings(s);
} }
// Legacy migration: sleepCoverOverlay was a Toggle (0=off, 1=on). Now it's a 4-way Enum:
// {WHITE(0), GRAY(1), BLACK(2), OFF(3)}. Translate old values before the generic loop clamps.
if (!doc["sleepCoverOverlay"].isNull()) {
uint8_t legacyOverlay = doc["sleepCoverOverlay"] | (uint8_t)0;
if (legacyOverlay == 0) {
s.sleepCoverOverlay = 3; // OFF
doc["sleepCoverOverlay"] = 3;
if (needsResave) *needsResave = true;
} else if (legacyOverlay == 1) {
s.sleepCoverOverlay = 1; // GRAY (old "on" = gray dither)
}
}
for (const auto& info : getSettingsList()) { for (const auto& info : getSettingsList()) {
if (!info.key) continue; if (!info.key) continue;
// Dynamic entries (KOReader etc.) are stored in their own files — skip. // Dynamic entries (KOReader etc.) are stored in their own files — skip.
+21 -12
View File
@@ -5,6 +5,7 @@
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include <HalStorage.h> #include <HalStorage.h>
#include <I18n.h> #include <I18n.h>
#include <Serialization.h>
#include <Txt.h> #include <Txt.h>
#include <Xtc.h> #include <Xtc.h>
@@ -155,8 +156,8 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
uint32_t totalPages = xtc.getPageCount(); uint32_t totalPages = xtc.getPageCount();
float progress = xtc.calculateProgress(currentPage) * 100.0f; float progress = xtc.calculateProgress(currentPage) * 100.0f;
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "Reading progress: Page %lu/%u - %.0f%%", (unsigned long)currentPage + 1, snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS), (unsigned long)currentPage + 1, totalPages,
totalPages, progress); progress);
info.progressText = buf; info.progressText = buf;
} }
f.close(); f.close();
@@ -176,8 +177,15 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
uint32_t totalPages = 0; uint32_t totalPages = 0;
FsFile indexFile; FsFile indexFile;
if (Storage.openFileForRead("SLP", txt.getCachePath() + "/index.bin", indexFile)) { if (Storage.openFileForRead("SLP", txt.getCachePath() + "/index.bin", indexFile)) {
indexFile.seek(32); uint32_t magic;
if (indexFile.read(reinterpret_cast<uint8_t*>(&totalPages), sizeof(totalPages)) == sizeof(totalPages)) { serialization::readPod(indexFile, magic);
uint8_t version;
serialization::readPod(indexFile, version);
static constexpr uint32_t INDEX_CACHE_MAGIC = 0x54585449; // "TXTI"
static constexpr uint8_t INDEX_CACHE_VERSION = 2;
if (magic == INDEX_CACHE_MAGIC && version == INDEX_CACHE_VERSION) {
indexFile.seek(32);
serialization::readPod(indexFile, totalPages);
} }
indexFile.close(); indexFile.close();
} }
@@ -185,12 +193,12 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
if (totalPages > 0) { if (totalPages > 0) {
float progress = (currentPage + 1) * 100.0f / totalPages; float progress = (currentPage + 1) * 100.0f / totalPages;
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "Reading progress: Page %lu/%u - %.0f%%", (unsigned long)currentPage + 1, snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS), (unsigned long)currentPage + 1, totalPages,
totalPages, progress); progress);
info.progressText = buf; info.progressText = buf;
} else { } else {
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "Reading progress: Page %lu", (unsigned long)currentPage + 1); snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS_NO_TOTAL), (unsigned long)currentPage + 1);
info.progressText = buf; info.progressText = buf;
} }
} }
@@ -219,13 +227,14 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
const auto tocItem = epub.getTocItem(tocIndex); const auto tocItem = epub.getTocItem(tocIndex);
info.chapterName = tocItem.title; info.chapterName = tocItem.title;
char suffix[64]; char suffix[64];
snprintf(suffix, sizeof(suffix), " - Page %d/%d - %.0f%%", currentPage + 1, pageCount, bookProgress); snprintf(suffix, sizeof(suffix), tr(STR_OVERLAY_CHAPTER_PAGE_SUFFIX), currentPage + 1, pageCount,
bookProgress);
info.progressSuffix = suffix; info.progressSuffix = suffix;
info.progressText = "Chapter: " + info.chapterName + info.progressSuffix; info.progressText = std::string(tr(STR_CHAPTER_PREFIX)) + info.chapterName + info.progressSuffix;
} else { } else {
char buf[80]; char buf[80];
snprintf(buf, sizeof(buf), "Reading progress: Page %d/%d - %.0f%%", currentPage + 1, pageCount, snprintf(buf, sizeof(buf), tr(STR_OVERLAY_READING_PROGRESS), (unsigned long)currentPage + 1,
bookProgress); (unsigned)pageCount, bookProgress);
info.progressText = buf; info.progressText = buf;
} }
} }
@@ -341,7 +350,7 @@ void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const {
if (hasProgress) { if (hasProgress) {
std::string progressStr; std::string progressStr;
if (!overlayInfo.chapterName.empty()) { if (!overlayInfo.chapterName.empty()) {
const std::string prefix = "Chapter: "; const std::string prefix = tr(STR_CHAPTER_PREFIX);
const int prefixWidth = renderer.getTextWidth(UI_10_FONT_ID, prefix.c_str()); const int prefixWidth = renderer.getTextWidth(UI_10_FONT_ID, prefix.c_str());
const int suffixWidth = renderer.getTextWidth(UI_10_FONT_ID, overlayInfo.progressSuffix.c_str()); const int suffixWidth = renderer.getTextWidth(UI_10_FONT_ID, overlayInfo.progressSuffix.c_str());
const int maxChapterWidth = availableWidth - prefixWidth - suffixWidth; const int maxChapterWidth = availableWidth - prefixWidth - suffixWidth;