Fix issue with missing strings in I18n.cpp

This commit is contained in:
Henrik Rydgård committed 2026-01-22 01:30:38 +01:00
1 parent 3c4adc3e66
commit 45c029cd7c
2 files changed
+20 -21

No files matched your search

+18 -19
View File
@@ -85,15 +85,14 @@ std::string_view I18NCategory::T(std::string_view key, std::string_view def) {
if (key != "Font") {
// Font is allowed to be missing.
INFO_LOG(Log::UI, "Missing translation [%s] %.*s (%.*s)", name_.c_str(), STR_VIEW(key), STR_VIEW(def));
std::lock_guard<std::mutex> guard(missedKeyLock_);
std::string missedKey(key);
if (!def.empty())
missedKeyLog_[missedKey] = def;
else
missedKeyLog_[missedKey] = missedKey;
return !def.empty() ? def : key;
}
std::lock_guard<std::mutex> guard(missedKeyLock_);
std::string missedKey(key);
if (!def.empty())
missedKeyLog_[missedKey] = def;
else
missedKeyLog_[missedKey] = missedKey;
return !def.empty() ? def : key;
}
}
@@ -106,17 +105,17 @@ const char *I18NCategory::T_cstr(const char *key, const char *def) {
// Too early. This is probably in desktop-ui translation.
return def ? def : key;
}
if (key != "Font") {
INFO_LOG(Log::UI, "Missing translation %s (%s)", key, def);
}
std::lock_guard<std::mutex> guard(missedKeyLock_);
std::string missedKey(key);
if (def)
missedKeyLog_[missedKey] = def;
else
missedKeyLog_[missedKey] = std::string(key);
return def ? def : key;
if (missedKey != "Font") {
INFO_LOG(Log::UI, "Missing translation %s (%s)", key, def);
std::lock_guard<std::mutex> guard(missedKeyLock_);
if (def)
missedKeyLog_[missedKey] = def;
else
missedKeyLog_[missedKey] = std::string(key);
return def ? def : key;
}
}
}
@@ -130,7 +129,7 @@ void I18NCategory::SetMap(const std::map<std::string, std::string> &m) {
}
}
std::map<std::string, std::string> I18NCategory::Missed() const {
std::map<std::string, std::string, std::less<>> I18NCategory::Missed() const {
std::lock_guard<std::mutex> guard(missedKeyLock_);
return missedKeyLog_;
}
+2 -2
View File
@@ -81,7 +81,7 @@ public:
// Try to avoid this. Still useful in snprintf.
const char *T_cstr(const char *key, const char *def = nullptr);
std::map<std::string, std::string> Missed() const;
std::map<std::string, std::string, std::less<>> Missed() const;
const std::map<std::string, I18NEntry, std::less<>> &GetMap() { return map_; }
void ClearMissed() { missedKeyLog_.clear(); }
@@ -94,7 +94,7 @@ private:
// std::less<> is needed to be able to look up string_views in a string-keyed map.
std::map<std::string, I18NEntry, std::less<>> map_;
mutable std::mutex missedKeyLock_;
std::map<std::string, std::string> missedKeyLog_;
std::map<std::string, std::string, std::less<>> missedKeyLog_;
std::string name_;
// Noone else can create these.