From fca86c4703ecc6061bfe1fb77c0e2e4e428a4a30 Mon Sep 17 00:00:00 2001 From: Karthik Date: Wed, 8 Jul 2026 21:10:03 +0530 Subject: [PATCH] tdf#172504: Use localized table style names This is a regression from 4fb31ea85f94c0cffba2282a119811833e584570, table style names were no longer localized. Signed-off-by: Karthik Change-Id: I02d0e9cbcce24a6a2747e43c4cf5fe4324e1ad3b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207825 Tested-by: Jenkins Reviewed-by: Heiko Tietze --- include/svx/TableAutoFmt.hxx | 4 ++ include/svx/strings.hrc | 1 + svx/source/table/tableautofmt.cxx | 44 +++++++++++++++++++ svx/source/table/tablestylesparser.cxx | 16 ++++--- sw/inc/strings.hrc | 2 - .../core/doc/DocumentStylePoolManager.cxx | 8 ++-- sw/source/core/doc/tblafmt.cxx | 2 +- sw/source/core/unocore/unostyle.cxx | 4 +- sw/source/uibase/shells/basesh.cxx | 5 ++- 9 files changed, 69 insertions(+), 17 deletions(-) diff --git a/include/svx/TableAutoFmt.hxx b/include/svx/TableAutoFmt.hxx index 213e4105871f..ba7ea4efccd3 100644 --- a/include/svx/TableAutoFmt.hxx +++ b/include/svx/TableAutoFmt.hxx @@ -202,6 +202,10 @@ public: virtual size_t size() const = 0; void ResetParent(std::u16string_view rName); + /** Translate built-in table style names between programmatic name and localized UI name. */ + static OUString MapProgToUIName(std::u16string_view rProgName); + static OUString MapUIToProgName(std::u16string_view rUIName); + static const SfxItemPropertySet& GetTablePropertySet(); bool Load(bool bWriter); diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc index ce28ed695f72..0c32b92db622 100644 --- a/include/svx/strings.hrc +++ b/include/svx/strings.hrc @@ -677,6 +677,7 @@ #define RID_SVXSTR_COLOR_PINK NC_("RID_SVXSTR_COLOR_PINK", "Pink") #define RID_SVXSTR_COLOR_TURQUOISE NC_("RID_SVXSTR_COLOR_TURQUOISE", "Turquoise") /* 16 old AutoFormat Table Styles */ +#define RID_SVXSTR_TBLAFMT_DEFAULT_STYLE NC_("RID_SVXSTR_TBLAFMT_DEFAULT_STYLE", "Default Style") #define RID_SVXSTR_TBLAFMT_3D NC_("RID_SVXSTR_TBLAFMT_3D", "3D") #define RID_SVXSTR_TBLAFMT_BLACK1 NC_("RID_SVXSTR_TBLAFMT_BLACK1", "Black 1") #define RID_SVXSTR_TBLAFMT_BLACK2 NC_("RID_SVXSTR_TBLAFMT_BLACK2", "Black 2") diff --git a/svx/source/table/tableautofmt.cxx b/svx/source/table/tableautofmt.cxx index 3e9903fc062d..559eeeb97a63 100644 --- a/svx/source/table/tableautofmt.cxx +++ b/svx/source/table/tableautofmt.cxx @@ -42,7 +42,11 @@ common functionality of SwTableAutoFormatTable and ScAutoFormat #include #include #include +#include +#include #include +#include +#include using namespace com::sun::star::beans; using namespace com::sun::star; @@ -421,6 +425,38 @@ void SvxAutoFormatData::ResetAutoFormat(SvxAutoFormatData& pOld) SvxAutoFormat::~SvxAutoFormat() = default; +const std::map getTranslatedStyleNames = { + { u"Default Style"_ustr, RID_SVXSTR_TBLAFMT_DEFAULT_STYLE }, + { u"Academic"_ustr, RID_SVXSTR_TBLAFMT_LO6_ACADEMIC }, + { u"Box List Blue"_ustr, RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_BLUE }, + { u"Box List Green"_ustr, RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_GREEN }, + { u"Box List Red"_ustr, RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_RED }, + { u"Box List Yellow"_ustr, RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_YELLOW }, + { u"Elegant"_ustr, RID_SVXSTR_TBLAFMT_LO6_ELEGANT }, + { u"Financial"_ustr, RID_SVXSTR_TBLAFMT_LO6_FINANCIAL }, + { u"Simple Grid Columns"_ustr, RID_SVXSTR_TBLAFMT_LO6_SIMPLE_GRID_COLUMNS }, + { u"Simple Grid Rows"_ustr, RID_SVXSTR_TBLAFMT_LO6_SIMPLE_GRID_ROWS }, + { u"Simple List Shaded"_ustr, RID_SVXSTR_TBLAFMT_LO6_SIMPLE_LIST_SHADED }, +}; + +OUString SvxAutoFormat::MapProgToUIName(std::u16string_view rProgName) +{ + const OUString aProgName(rProgName); + auto it = getTranslatedStyleNames.find(aProgName); + return it != getTranslatedStyleNames.end() ? SvxResId(it->second) : aProgName; +} + +OUString SvxAutoFormat::MapUIToProgName(std::u16string_view rUIName) +{ + const OUString aUIName(rUIName); + for (auto const & [ rProgName, rResId ] : getTranslatedStyleNames) + { + if (aUIName == SvxResId(rResId)) + return rProgName; + } + return aUIName; +} + void SvxAutoFormat::ResetParent(std::u16string_view rName) { OUString sParent; @@ -470,6 +506,14 @@ bool SvxAutoFormat::Load(bool bWriter) aInputSource.sSystemId = sPath; xImport->parseStream(aInputSource); + + for (size_t i = 0; i < size(); ++i) + { + SvxAutoFormatData* pData = GetData(i); + pData->SetName(MapProgToUIName(pData->GetName())); + if (!pData->GetParent().isEmpty()) + pData->SetParent(MapProgToUIName(pData->GetParent())); + } return true; } catch (const uno::Exception& e) diff --git a/svx/source/table/tablestylesparser.cxx b/svx/source/table/tablestylesparser.cxx index 0c5c6f74505f..e5b018c6cd2f 100644 --- a/svx/source/table/tablestylesparser.cxx +++ b/svx/source/table/tablestylesparser.cxx @@ -596,15 +596,18 @@ void SvxTableStylesExport::ExportStyles() for (size_t i = 0; i < mpAutoFormat.size(); i++) { const SvxAutoFormatData* pData = mpAutoFormat.GetData(i); - const OUString& sTemplateName = pData->GetName(); + const OUString sTemplateName = SvxAutoFormat::MapUIToProgName(pData->GetName()); + const OUString sParentProgName + = !pData->GetParent().isEmpty() ? SvxAutoFormat::MapUIToProgName(pData->GetParent()) + : OUString(); auto it = CellFieldToIndex.begin(); while (it != CellFieldToIndex.end()) { OUString sStyleName = sTemplateName.replaceAll(" ", "-") + "." + it->first; OUString sParentName; - if (pData->GetParent().getLength()) - sParentName = pData->GetParent().replaceAll(" ", "-") + "." + it->first; + if (!sParentProgName.isEmpty()) + sParentName = sParentProgName.replaceAll(" ", "-") + "." + it->first; exportCellStyle(*pData->GetField(it->second), sStyleName, sParentName); it++; @@ -623,7 +626,9 @@ void SvxTableStylesExport::ExportStyles() void SvxTableStylesExport::exportTableTemplate(const SvxAutoFormatData& rData) { - AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, rData.GetName()); + const OUString sProgName = SvxAutoFormat::MapUIToProgName(rData.GetName()); + + AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, sProgName); if (rData.UseFirstRowStyles()) AddAttribute(XML_NAMESPACE_TABLE, XML_USE_FIRST_ROW_STYLES, "true"); if (rData.UseLastRowStyles()) @@ -641,8 +646,7 @@ void SvxTableStylesExport::exportTableTemplate(const SvxAutoFormatData& rData) for (sal_uInt16 i = 0; i < 16; i++) { - OUString sCellStyleName - = rData.GetName().replaceAll(" ", "-") + "." + IndexToCellField.at(i); + OUString sCellStyleName = sProgName.replaceAll(" ", "-") + "." + IndexToCellField.at(i); AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sCellStyleName); if (i < 10) diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index f3143630bb0b..a4189db2da90 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -234,8 +234,6 @@ #define STR_COLUMN_VALUESET_ITEM2 NC_("STR_COLUMN_VALUESET_ITEM2", "3 columns with equal size") #define STR_COLUMN_VALUESET_ITEM3 NC_("STR_COLUMN_VALUESET_ITEM3", "2 columns with different size (left > right)") #define STR_COLUMN_VALUESET_ITEM4 NC_("STR_COLUMN_VALUESET_ITEM4", "2 columns with different size (left < right)") -// Table styles, Writer internal, others are taken from Svx -#define STR_TABSTYLE_DEFAULT NC_("STR_TABSTYLE_DEFAULT", "Default Style") #define STR_PARAGRAPHSTYLEFAMILY NC_("STR_PARAGRAPHSTYLEFAMILY", "Paragraph Styles") #define STR_CHARACTERSTYLEFAMILY NC_("STR_CHARACTERSTYLEFAMILY", "Character Styles") diff --git a/sw/source/core/doc/DocumentStylePoolManager.cxx b/sw/source/core/doc/DocumentStylePoolManager.cxx index 901bfa6ac373..99e3fe357064 100644 --- a/sw/source/core/doc/DocumentStylePoolManager.cxx +++ b/sw/source/core/doc/DocumentStylePoolManager.cxx @@ -543,9 +543,8 @@ const TranslateId STR_POOLNUMRULE_NUM_ARY[] = // RES_POOL_TABLESTYLE_TYPE in sw/inc/poolfmt.hxx const TranslateId STR_TABSTYLE_ARY[] = { - // XXX MUST be in order, Writer first, then Svx old, then Svx new - // 1 Writer resource string - STR_TABSTYLE_DEFAULT, + // XXX MUST be in order: default style, then Svx old, then Svx new + RID_SVXSTR_TBLAFMT_DEFAULT_STYLE, // 16 old styles Svx resource strings RID_SVXSTR_TBLAFMT_3D, RID_SVXSTR_TBLAFMT_BLACK1, @@ -2847,9 +2846,8 @@ const std::vector& SwStyleNameMapper::GetTableStyleUINameArray() auto it = s_aTableStyleUINameArray.find(rCurrentLanguage); if (it == s_aTableStyleUINameArray.end()) it = s_aTableStyleUINameArray.emplace(rCurrentLanguage, - // 1 Writer resource string (XXX if this ever changes rather use offset math) lcl_NewUINameArray(STR_TABSTYLE_ARY, std::ssize(STR_TABSTYLE_ARY), - static_cast(std::ssize(STR_TABSTYLE_ARY) - 1))).first; + static_cast(std::ssize(STR_TABSTYLE_ARY)))).first; return it->second; } diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx index 89c97483f72c..cbd3d53ffbdc 100644 --- a/sw/source/core/doc/tblafmt.cxx +++ b/sw/source/core/doc/tblafmt.cxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 4d82e4b06c91..957622bdc8ea 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -36,7 +36,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -1083,7 +1085,7 @@ void SwXStyleFamily::insertByName(const OUString& rProgName, const uno::Any& rEl pNewStyle->setName(rProgName); // insertByName sets the element name if (pNewStyle->getParentStyle().isEmpty()) - pNewStyle->setParentStyle(SwResId(STR_TABSTYLE_DEFAULT)); + pNewStyle->setParentStyle(SvxResId(RID_SVXSTR_TBLAFMT_DEFAULT_STYLE)); m_pDocShell->GetDoc()->GetTableStyles().AddAutoFormat(*pNewStyle->GetTableFormat()); pNewStyle->SetPhysical(); diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index 27305914b59a..63c9a1953e1f 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -3265,7 +3266,7 @@ void SwBaseShell::InsertTable( SfxRequest& _rRequest ) // Use Default Style if no autoformat is provided else { - aAutoNameIn = SvxResId(STR_TABSTYLE_DEFAULT); + aAutoNameIn = SvxResId(RID_SVXSTR_TBLAFMT_DEFAULT_STYLE); pTAFormatIn.reset(new SwTableAutoFormat(rTableTable[0])); } @@ -3320,7 +3321,7 @@ void SwBaseShell::InsertTable( SfxRequest& _rRequest ) // Set Default Style name is no autoformat is provided if (aAutoNameIn.isEmpty()) - aAutoNameIn = SvxResId(STR_TABSTYLE_DEFAULT); + aAutoNameIn = SvxResId(RID_SVXSTR_TBLAFMT_DEFAULT_STYLE); InsertTableImpl( rSh, rTempView, UIName(aTableNameIn), nRowsIn, nColsIn, aInsTableOptsIn, TableStyleName(aAutoNameIn), pTAFormatIn );