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 546ad5d17d3e363b75337c336cfb2b2f8acc55e3 Author: Rafael Lima <rafael.palma.l...@gmail.com> AuthorDate: Thu Jan 19 13:12:42 2023 +0000 Commit: Heiko Tietze <heiko.tie...@documentfoundation.org> CommitDate: Tue Feb 21 16:30:38 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 diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc index 8228eea8f1fa..0cd2d2cd4566 100644 --- a/cui/inc/strings.hrc +++ b/cui/inc/strings.hrc @@ -406,4 +406,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 3c66f4ba49d5..2cb20a2650fa 100644 --- a/cui/source/options/optcolor.cxx +++ b/cui/source/options/optcolor.cxx @@ -160,6 +160,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 @@ -787,8 +814,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(); @@ -809,8 +836,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 18aa40bbfa8b..b7d704d43f81 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"/> @@ -440,7 +440,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>