diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2022-05-01 16:52:30 -0400 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-09-22 08:29:16 +0200 |
commit | 90e3244aa6c15a42c5c86ebe5b36592085de9c79 (patch) | |
tree | 0e3c08009d0ae96fcd062730e305e154bca4e4eb /sfx2 | |
parent | 4c2a9f46c1a7f4495c08f84a48d984364dedffa3 (diff) |
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 language used for loading before saving
to avoid such issues.
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Change-Id: I6675204bb68ea33b1395c779a64ab3e9b339d73e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135482
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
(cherry picked from commit 4b7b449bbdc51557f62131a3b467b34ad39e8547)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140361
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 33 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 8 |
2 files changed, 41 insertions, 0 deletions
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 275f693a23f9..83d28956ebee 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -92,6 +92,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> @@ -103,6 +104,7 @@ #include <sfx2/docfac.hxx> #include <appopen.hxx> #include <objshimp.hxx> +#include <sfx2/lokhelper.hxx> #include <sfx2/strings.hrc> #include <sfx2/sfxsids.hrc> #include <sfx2/dispatch.hxx> @@ -3208,6 +3210,37 @@ bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium ) pImpl->aBasicManager.storeLibrariesToStorage( xStorage ); } #endif + + if (comphelper::LibreOfficeKit::isActive()) + { + // 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 use the loader's language. + const LanguageTag viewLanguage = comphelper::LibreOfficeKit::getLanguageTag(); + const LanguageTag loadLanguage = SfxLokHelper::getLoadLanguage(); + + // Use the default language for saving and restore later if necessary. + bool restoreLanguage = false; + if (viewLanguage != loadLanguage) + { + restoreLanguage = true; + comphelper::LibreOfficeKit::setLanguageTag(loadLanguage); + } + + // 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); + } + return SaveAs( rMedium ); } else return false; diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index aa38c5dbee98..a082aeff110d 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -73,6 +73,7 @@ int DisableCallbacks::m_nDisabled = 0; namespace { LanguageTag g_defaultLanguageTag("en-US", true); +LanguageTag g_loadLanguageTag("en-US", true); //< The language used to load. LOKDeviceFormFactor g_deviceFormFactor = LOKDeviceFormFactor::UNKNOWN; } @@ -279,6 +280,13 @@ void SfxLokHelper::setDefaultLanguage(const OUString& rBcp47LanguageTag) g_defaultLanguageTag = LanguageTag(rBcp47LanguageTag, true); } +const LanguageTag& SfxLokHelper::getLoadLanguage() { return g_loadLanguageTag; } + +void SfxLokHelper::setLoadLanguage(const OUString& rBcp47LanguageTag) +{ + g_loadLanguageTag = LanguageTag(rBcp47LanguageTag, true); +} + void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag) { std::vector<SfxViewShell*>& rViewArr = SfxGetpApp()->GetViewShells_Impl(); |