[Scummvm-git-logs] scummvm master -> 3eb74d00a84100a07b05ff98163084311461af52
sev-
noreply at scummvm.org
Mon Mar 2 16:41:43 UTC 2026
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
3eb74d00a8 COMMON: Properly process translations with context in TransMan in .po
Commit: 3eb74d00a84100a07b05ff98163084311461af52
https://github.com/scummvm/scummvm/commit/3eb74d00a84100a07b05ff98163084311461af52
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-03-02T17:41:23+01:00
Commit Message:
COMMON: Properly process translations with context in TransMan in .po
Changed paths:
common/translation.cpp
common/translation.h
diff --git a/common/translation.cpp b/common/translation.cpp
index 1107088cb39..5d246b6a6a2 100644
--- a/common/translation.cpp
+++ b/common/translation.cpp
@@ -120,7 +120,7 @@ U32String TranslationManager::getTranslation(const char *message) const {
return getTranslation(message, nullptr);
}
-U32String TranslationManager::getPoTranslation(const char* message) const {
+U32String TranslationManager::getPoTranslation(const char *message) const {
if (_currentTranslationMessages.empty() || *message == '\0')
return U32String(message);
@@ -132,9 +132,27 @@ U32String TranslationManager::getPoTranslation(const char* message) const {
return _currentTranslationMessages[messageIndex].msgstr.decode();
}
+U32String TranslationManager::getPoTranslation(const char *message, const char *context) const {
+ if (_currentTranslationMessages.empty() || *message == '\0')
+ return U32String(message);
+
+ Common::String key = message;
+ if (context && *context != '\0') {
+ key += "\x04"; // Use the same separation mark as gettext does for context
+ key += context;
+ }
+
+ int messageIndex = _poTranslations.getValOrDefault(key.c_str(), -1);
+
+ if (messageIndex == -1)
+ return U32String(message);
+
+ return _currentTranslationMessages[messageIndex].msgstr.decode();
+}
+
U32String TranslationManager::getTranslation(const char *message, const char *context) const {
if (_usingPo)
- return getPoTranslation(message);
+ return getPoTranslation(message, context);
// If no language is set or message is empty, return msgid as is
if (_currentTranslationMessages.empty() || *message == '\0')
@@ -447,8 +465,14 @@ bool TranslationManager::loadLanguagePo(int index) {
_currentTranslationMessages.reserve(numEntries);
for (int i = 0; i < numEntries; ++i) {
const Common::PlainPoMessageEntry *entry = poData->entry(i);
+ Common::String key = entry->msgid;
+
+ if (entry->msgctxt) {
+ key += "\x04"; // Use the same separation mark as gettext does for context
+ key += entry->msgctxt;
+ }
- _poTranslations[entry->msgid] = i;
+ _poTranslations[key] = i;
PoMessageEntry engineEntry;
engineEntry.msgid = i;
engineEntry.msgstr = entry->msgstr;
diff --git a/common/translation.h b/common/translation.h
index 7fffe31031b..479ab2b952f 100644
--- a/common/translation.h
+++ b/common/translation.h
@@ -257,11 +257,12 @@ private:
/**
* Return the translation of @p message into the current language loaded from a .po file.
- *
+ *
* In case the message is not found in the translation catalog,
* return the original untranslated message, as a U32String.
*/
U32String getPoTranslation(const char *message) const;
+ U32String getPoTranslation(const char *message, const char *context) const;
/**
* Load the translation for the given language from its .po file.
More information about the Scummvm-git-logs
mailing list