include/vcl/builder.hxx       |    2 ++
 vcl/source/window/builder.cxx |   31 +++++++++++++++++++------------
 2 files changed, 21 insertions(+), 12 deletions(-)

New commits:
commit b2a4833ee2a52358ad3dba170d9e4b34cc87c136
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Aug 12 13:24:46 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Tue Aug 13 07:17:29 2024 +0200

    tdf#130857 VclBuilder: Extract helper to finalize value
    
    Extract helper method `BuilderBase::finalizeValue`
    to "finalize" a value, i.e. translate (if applicable)
    and apply the string hook (if set) from
    `VclBuilder::handleItems`.
    
    It will be reused in `VclBuilder::collectProperty`
    in an upcoming commit to reduce duplication.
    
    Change-Id: I76a41dbe9c830de02cb38b17d3587d49f64d0ff8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171788
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index d91e3b8c51b5..4682e0951756 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -84,6 +84,8 @@ protected:
 
     bool isLegacy() { return m_bLegacy; }
     const std::locale& getResLocale() const;
+    OUString finalizeValue(const OString& rContext, const OString& rValue,
+                           const bool bTranslate) const;
 
     virtual void resetParserState();
 
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 113f6bb82af4..003dd81a6fea 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -457,6 +457,24 @@ const std::locale& BuilderBase::getResLocale() const
     return m_pParserState->m_aResLocale;
 }
 
+OUString BuilderBase::finalizeValue(const OString& rContext, const OString& 
rValue,
+                                    const bool bTranslate) const
+{
+    OUString sFinalValue;
+    if (bTranslate)
+    {
+        sFinalValue
+            = Translate::get(TranslateId{ rContext.getStr(), rValue.getStr() 
}, getResLocale());
+    }
+    else
+        sFinalValue = OUString::fromUtf8(rValue);
+
+    if (ResHookProc pStringReplace = Translate::GetReadStringHook())
+        sFinalValue = (*pStringReplace)(sFinalValue);
+
+    return sFinalValue;
+}
+
 void BuilderBase::resetParserState() { m_pParserState.reset(); }
 
 VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const 
OUString& sUIFile,
@@ -3192,18 +3210,7 @@ std::vector<ComboBoxTextItem> 
VclBuilder::handleItems(xmlreader::XmlReader &read
                     xmlreader::XmlReader::Text::Raw, &name, &nsId);
 
                 OString sValue(name.begin, name.length);
-                OUString sFinalValue;
-                if (bTranslated)
-                {
-                    sFinalValue = Translate::get(TranslateId{ 
sContext.getStr(), sValue.getStr() },
-                                                 getResLocale());
-                }
-                else
-                    sFinalValue = OUString::fromUtf8(sValue);
-
-                if (ResHookProc pStringReplace = 
Translate::GetReadStringHook())
-                    sFinalValue = (*pStringReplace)(sFinalValue);
-
+                const OUString sFinalValue = finalizeValue(sContext, sValue, 
bTranslated);
                 aItems.emplace_back(sFinalValue, sId);
             }
         }

Reply via email to