cui/inc/strings.hrc                                  |    4 ++
 cui/source/options/optcolor.cxx                      |   35 ++++++++++++++++---
 officecfg/registry/data/org/openoffice/Office/UI.xcu |    6 +--
 3 files changed, 38 insertions(+), 7 deletions(-)

New commits:
commit 5dd7fbdf5f4afaa84f79373446f4f7e3b3e715b8
Author:     Rafael Lima <rafael.palma.l...@gmail.com>
AuthorDate: Thu Jan 19 13:12:42 2023 +0000
Commit:     Paris Oplopoios <parisop...@gmail.com>
CommitDate: Thu Mar 23 21:28:43 2023 +0000

    tdf#143660 Make color scheme names translatable
    
    The color scheme names defined in UI.xcu are currently not translatable.
    
    This patch makes them translatable by mapping the names in the UI.xcu file 
to a translated string.
    
    Change-Id: I10ab3bbcc9b028955c3c179558f8040b3b1d6c9d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145732
    Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org>
    Tested-by: Jenkins
    (cherry picked from commit 546ad5d17d3e363b75337c336cfb2b2f8acc55e3)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149244
    Tested-by: Paris Oplopoios <parisop...@gmail.com>
    Reviewed-by: Paris Oplopoios <parisop...@gmail.com>

diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc
index c45c2d4d6956..cb90ffe6d7df 100644
--- a/cui/inc/strings.hrc
+++ b/cui/inc/strings.hrc
@@ -404,4 +404,8 @@
 
 #define RID_LANGUAGETOOL_LEAVE_EMPTY                
NC_("RID_LANGUAGETOOL_LEAVE_EMPTY", "Leave this field empty to use the free 
version")
 
+// Translatable names of color schemes
+#define RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC      
NC_("RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", "Automatic")
+#define RID_COLOR_SCHEME_LIBREOFFICE_DARK           
NC_("RID_COLOR_SCHEME_LIBREOFFICE_DARK", "Dark")
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/options/optcolor.cxx b/cui/source/options/optcolor.cxx
index 70345fc5e40f..eb13b442232a 100644
--- a/cui/source/options/optcolor.cxx
+++ b/cui/source/options/optcolor.cxx
@@ -159,6 +159,33 @@ const vEntryInfo[] =
     #undef IDS
 };
 
+// Maps the names of default color schemes to the corresponding TranslateId
+std::map<OUString, OUString> const vColorSchemes = {
+    {"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", 
CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC)},
+    {"COLOR_SCHEME_LIBREOFFICE_DARK",      
CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_DARK)}
+};
+
+// If the color scheme name has a translated string, then return the 
translation
+// Or else simply return the input string
+// For non-translatable color schemes, the ID and the name are the same
+OUString lcl_SchemeIdToTranslatedName(const OUString& sSchemeId)
+{
+    auto it = vColorSchemes.find(sSchemeId);
+    if (it != vColorSchemes.end())
+        return it->second;
+    return sSchemeId;
+}
+
+// Given a translated color scheme name, return the scheme ID used in the 
UI.xcu file
+// For non-translatable color schemes, the ID and the name are the same
+OUString lcl_TranslatedNameToSchemeId(const OUString& sName)
+{
+    for (auto it = vColorSchemes.begin(); it != vColorSchemes.end(); ++it)
+        if (it->second == sName)
+            return it->first;
+    return sName;
+}
+
 // ColorConfigWindow_Impl
 
 class ColorConfigWindow_Impl
@@ -786,8 +813,8 @@ void SvxColorOptionsTabPage::Reset( const SfxItemSet* )
     m_xColorSchemeLB->clear();
     const uno::Sequence< OUString >  aSchemes = pColorConfig->GetSchemeNames();
     for(const OUString& s : aSchemes)
-        m_xColorSchemeLB->append_text(s);
-    m_xColorSchemeLB->set_active_text(pColorConfig->GetCurrentSchemeName());
+        m_xColorSchemeLB->append_text(lcl_SchemeIdToTranslatedName(s));
+    
m_xColorSchemeLB->set_active_text(lcl_SchemeIdToTranslatedName(pColorConfig->GetCurrentSchemeName()));
     m_xColorSchemeLB->save_value();
     m_xDeleteSchemePB->set_sensitive( aSchemes.getLength() > 1 );
     UpdateColorConfig();
@@ -808,8 +835,8 @@ void SvxColorOptionsTabPage::UpdateColorConfig()
 
 IMPL_LINK(SvxColorOptionsTabPage, SchemeChangedHdl_Impl, weld::ComboBox&, 
rBox, void)
 {
-    pColorConfig->LoadScheme(rBox.get_active_text());
-    pExtColorConfig->LoadScheme(rBox.get_active_text());
+    
pColorConfig->LoadScheme(lcl_TranslatedNameToSchemeId(rBox.get_active_text()));
+    
pExtColorConfig->LoadScheme(lcl_TranslatedNameToSchemeId(rBox.get_active_text()));
     UpdateColorConfig();
 }
 
diff --git a/officecfg/registry/data/org/openoffice/Office/UI.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI.xcu
index ec29706fd030..93e95f0c5c65 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI.xcu
@@ -134,10 +134,10 @@
   </node>
   <node oor:name="ColorScheme">
     <prop oor:name="CurrentColorScheme">
-      <value>${PRODUCTNAME}</value>
+      <value>COLOR_SCHEME_LIBREOFFICE_AUTOMATIC</value>
     </prop>
     <node oor:name="ColorSchemes">
-      <node oor:name="${PRODUCTNAME}" oor:op="replace">
+      <node oor:name="COLOR_SCHEME_LIBREOFFICE_AUTOMATIC" oor:op="replace">
         <node oor:name="DocColor">
           <prop oor:name="Color">
             <value xsi:nil="true"/>
@@ -435,7 +435,7 @@
           </prop>
         </node>
       </node>
-      <node oor:name="${PRODUCTNAME} Dark" oor:op="replace">
+      <node oor:name="COLOR_SCHEME_LIBREOFFICE_DARK" oor:op="replace">
         <node oor:name="DocColor">
           <prop oor:name="Color">
             <value>1842204</value>

Reply via email to