sfx2/source/doc/objstor.cxx |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

New commits:
commit f4ef1e3e580f7a590496d62aaa3dc7e092510a9c
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 10:43:13 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>

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;

Reply via email to