tdf#172504: Use localized table style names

This is a regression from 4fb31ea85f,
table style names were no longer localized.

Signed-off-by: Karthik <karthik.godha@collabora.com>
Change-Id: I02d0e9cbcce24a6a2747e43c4cf5fe4324e1ad3b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207825
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
This commit is contained in:
Karthik
2026-07-23 12:53:22 +02:00
committed by Karthik Godha
parent 855b66846b
commit fca86c4703
9 changed files with 69 additions and 17 deletions
+4
View File
@@ -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);
+1
View File
@@ -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")
+44
View File
@@ -42,7 +42,11 @@ common functionality of SwTableAutoFormatTable and ScAutoFormat
#include <editeng/svxenum.hxx>
#include <svl/typedwhich.hxx>
#include <svx/TableStylesParser.hxx>
#include <svx/dialmgr.hxx>
#include <svx/strings.hrc>
#include <tools/stream.hxx>
#include <map>
#include <string_view>
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<OUString, TranslateId> 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)
+10 -6
View File
@@ -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)
-2
View File
@@ -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")
@@ -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<OUString>& 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<size_t>(std::ssize(STR_TABSTYLE_ARY) - 1))).first;
static_cast<size_t>(std::ssize(STR_TABSTYLE_ARY)))).first;
return it->second;
}
+1 -1
View File
@@ -23,7 +23,7 @@
#include <doc.hxx>
#include <tblafmt.hxx>
#include <cellatr.hxx>
#include <SwStyleNameMapper.hxx>
#include <swtypes.hxx>
#include <hintids.hxx>
#include <fmtornt.hxx>
#include <editsh.hxx>
+3 -1
View File
@@ -36,7 +36,9 @@
#include <svl/numformat.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
#include <svx/dialmgr.hxx>
#include <svx/pageitem.hxx>
#include <svx/strings.hrc>
#include <editeng/colritem.hxx>
#include <editeng/contouritem.hxx>
#include <editeng/crossedoutitem.hxx>
@@ -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();
+3 -2
View File
@@ -18,6 +18,7 @@
*/
#include <svx/dialmgr.hxx>
#include <svx/strings.hrc>
#include <config_features.h>
#include <config_fuzzers.h>
@@ -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 );