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

New commits:
commit 01a9f402db5840801e0eb004112bf19d5225f32c
Author:     Ashod Nakashian <[email protected]>
AuthorDate: Sun May 1 16:52:30 2022 -0400
Commit:     Michael Meeks <[email protected]>
CommitDate: Mon May 2 20:02:03 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 <[email protected]>
    Change-Id: Ibc0813de33cf7cf3528b0ff1d95560e799903fb0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133676
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Meeks <[email protected]>
    (cherry picked from commit f4ef1e3e580f7a590496d62aaa3dc7e092510a9c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133611

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 8d101e8aac04..e456f5ea951a 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -105,6 +105,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>
@@ -3158,6 +3159,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();
@@ -3180,6 +3186,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