summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2022-05-01 16:52:30 -0400
committerMichael Meeks <michael.meeks@collabora.com>2022-05-02 10:43:13 +0200
commitf4ef1e3e580f7a590496d62aaa3dc7e092510a9c (patch)
treee2f3b5c6613fd2718ce612f2d4647cbc429e421a
parentsvx: calculate object range before using it (diff)
downloadcore-f4ef1e3e580f7a590496d62aaa3dc7e092510a9c.tar.gz
core-f4ef1e3e580f7a590496d62aaa3dc7e092510a9c.zip
sw: restore UI language to en while saving
Because the XML writer used in sw invokes the translation logic, which uses the UI language, saving can fail in case there are multiple views with different langauges. This restores the default language before saving to avoid such issues and to make sure the document xml is generated in the default language. Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> Change-Id: Ibc0813de33cf7cf3528b0ff1d95560e799903fb0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133676 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r--sfx2/source/doc/objstor.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 7ccee4f3a970..238369b746e6 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -91,6 +91,7 @@
#include <osl/file.hxx>
#include <comphelper/scopeguard.hxx>
#include <comphelper/lok.hxx>
+#include <i18nlangtag/languagetag.hxx>
#include <sfx2/signaturestate.hxx>
#include <sfx2/app.hxx>
@@ -3168,6 +3169,11 @@ bool SfxObjectShell::LoadOwnFormat( SfxMedium& rMedium )
return false;
}
+namespace
+{
+static LanguageTag g_defaultLanguageTag("en-US", true);
+}
+
bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium )
{
uno::Reference< embed::XStorage > xStorage = rMedium.GetStorage();
@@ -3190,6 +3196,31 @@ bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium )
pImpl->aBasicManager.storeLibrariesToStorage( xStorage );
}
#endif
+
+ // Because XMLTextFieldExport::ExportFieldDeclarations (called from SwXMLExport)
+ // calls SwXTextFieldMasters::getByName, which in turn maps property names by
+ // calling SwStyleNameMapper::GetTextUINameArray, which uses
+ // SvtSysLocale().GetUILanguageTag() to do the mapping, saving indirectly depends
+ // on the UI language. This is an unfortunate depenency.
+ // Here we restore to English
+ const auto viewLanguage = comphelper::LibreOfficeKit::getLanguageTag();
+
+ // Use the default language for saving and restore later if necessary.
+ bool restoreLanguage = false;
+ if (comphelper::LibreOfficeKit::isActive() && viewLanguage != g_defaultLanguageTag)
+ {
+ restoreLanguage = true;
+ comphelper::LibreOfficeKit::setLanguageTag(g_defaultLanguageTag);
+ }
+
+ // Restore the view's original language automatically and as necessary.
+ const ::comphelper::ScopeGuard aGuard(
+ [&viewLanguage, restoreLanguage]()
+ {
+ if (restoreLanguage && viewLanguage != comphelper::LibreOfficeKit::getLanguageTag())
+ comphelper::LibreOfficeKit::setLanguageTag(viewLanguage);
+ });
+
return SaveAs( rMedium );
}
else return false;