summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorRafael Lima <rafael.palma.lima@gmail.com>2023-01-19 13:12:42 +0000
committerParis Oplopoios <parisoplop@gmail.com>2023-03-23 21:28:43 +0000
commit5dd7fbdf5f4afaa84f79373446f4f7e3b3e715b8 (patch)
tree44760f0f63fcafdcdfc723aae0c473b6f5cfd7cd /cui
parent517b089acd2099a2a755f65ef2cae7076399ee6e (diff)
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.tietze@documentfoundation.org> Tested-by: Jenkins (cherry picked from commit 546ad5d17d3e363b75337c336cfb2b2f8acc55e3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149244 Tested-by: Paris Oplopoios <parisoplop@gmail.com> Reviewed-by: Paris Oplopoios <parisoplop@gmail.com>
Diffstat (limited to 'cui')
-rw-r--r--cui/inc/strings.hrc4
-rw-r--r--cui/source/options/optcolor.cxx35
2 files changed, 35 insertions, 4 deletions
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();
}