From 62f5476dec90d7f2d91265f9e95ee1bd3846c0e9 Mon Sep 17 00:00:00 2001 From: leper Date: Wed, 30 Apr 2014 22:33:08 +0000 Subject: [PATCH] Add support for adding translation context to XML elements. Patch by Gallaecio. Add translation context to some lobby headers. This was SVN commit r15078. --- .../data/mods/public/gui/gamesetup/gamesetup.xml | 2 +- binaries/data/mods/public/gui/lobby/lobby.xml | 4 ++-- source/gui/CGUI.cpp | 14 ++++++++++++-- source/gui/COList.cpp | 14 ++++++++++++-- source/tools/i18n/potter/extractors.py | 2 ++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/binaries/data/mods/public/gui/gamesetup/gamesetup.xml b/binaries/data/mods/public/gui/gamesetup/gamesetup.xml index 5890ecf97c..01f6f657e4 100644 --- a/binaries/data/mods/public/gui/gamesetup/gamesetup.xml +++ b/binaries/data/mods/public/gui/gamesetup/gamesetup.xml @@ -95,7 +95,7 @@ - Match Type: + Map Type: Map Filter: diff --git a/binaries/data/mods/public/gui/lobby/lobby.xml b/binaries/data/mods/public/gui/lobby/lobby.xml index 5ad352dee1..6940b5a6f1 100644 --- a/binaries/data/mods/public/gui/lobby/lobby.xml +++ b/binaries/data/mods/public/gui/lobby/lobby.xml @@ -132,10 +132,10 @@ Map Name - Size + Size - Type + Type Players diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index f2dfc524a2..0002e5377e 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -1109,6 +1109,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec ATTR(on); ATTR(file); ATTR(id); + ATTR(context); // // Read Style and set defaults @@ -1290,8 +1291,17 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec CStr value(child.GetText()); if (!value.empty()) { - CStr translatedValue(L10n::Instance().Translate(value)); - object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true); + CStr context(child.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. + if (!context.empty()) + { + CStr translatedValue(L10n::Instance().TranslateWithContext(context, value)); + object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true); + } + else + { + CStr translatedValue(L10n::Instance().Translate(value)); + object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true); + } } } else // Ignore. diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp index 01b87c52ff..b84b4e3262 100644 --- a/source/gui/COList.cpp +++ b/source/gui/COList.cpp @@ -129,6 +129,7 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile ELMT(def); ELMT(translatableAttribute); ATTR(id); + ATTR(context); if (child.GetNodeName() == elmt_item) { @@ -198,8 +199,17 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile CStr value(grandchild.GetText()); if (!value.empty()) { - CStr translatedValue(L10n::Instance().Translate(value)); - oDef.m_Heading = translatedValue.FromUTF8(); + CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. + if (!context.empty()) + { + CStr translatedValue(L10n::Instance().TranslateWithContext(context, value)); + oDef.m_Heading = translatedValue.FromUTF8(); + } + else + { + CStr translatedValue(L10n::Instance().Translate(value)); + oDef.m_Heading = translatedValue.FromUTF8(); + } } } else // Ignore. diff --git a/source/tools/i18n/potter/extractors.py b/source/tools/i18n/potter/extractors.py index f227d90c52..c57f471ea9 100644 --- a/source/tools/i18n/potter/extractors.py +++ b/source/tools/i18n/potter/extractors.py @@ -413,6 +413,8 @@ class xml(Extractor): position += " ({attributes})".format(attributes=", ".join(attributes)) if "tagAsContext" in self.keywords[keyword]: context = keyword + if "context" in element.attrib: + context = element.get("context") if "comment" in element.attrib: comment = element.get("comment") comment = u" ".join(comment.split()) # Remove tabs, line breaks and unecessary spaces.