sfx2/source/doc/objstor.cxx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
New commits: commit 7e088fe43ae7c2647e634faa57e5905f39c4a522 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> AuthorDate: Sun May 1 16:52:30 2022 -0400 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Mon May 2 20:02:19 2022 +0200 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.nakash...@collabora.co.uk> Change-Id: Ibc0813de33cf7cf3528b0ff1d95560e799903fb0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133676 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Michael Meeks <michael.me...@collabora.com> (cherry picked from commit f4ef1e3e580f7a590496d62aaa3dc7e092510a9c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133610 diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 548ce34b1c21..65a340221223 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> @@ -3175,6 +3176,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(); @@ -3197,6 +3203,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;