[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - vcl/unx

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 18 12:52:27 UTC 2018


 vcl/unx/gtk3/gtk3gtkinst.cxx |   36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

New commits:
commit 47ff79610feee88283695fe148b2b03801517e3b
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Sep 18 09:53:54 2018 +0100
Commit:     Adolfo Jayme Barrientos <fitojb at ubuntu.com>
CommitDate: Tue Sep 18 14:52:05 2018 +0200

    tdf#119929 ensure .ui translation domain is bound before translation attempt
    
    Change-Id: Ib06b399f6c975c1c64594b0a294b10bc6a9f0a69
    Reviewed-on: https://gerrit.libreoffice.org/60667
    Reviewed-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>
    Tested-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>

diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 67db66dcdb08..0b855ebd4822 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -4945,6 +4945,7 @@ private:
     GtkBuilder* m_pBuilder;
     GSList* m_pObjectList;
     GtkWidget* m_pParentWidget;
+    gulong m_nNotifySignalId;
     std::vector<GtkButton*> m_aMnemonicButtons;
     std::vector<GtkLabel*> m_aMnemonicLabels;
 
@@ -5030,6 +5031,28 @@ private:
         }
     }
 
+    //GtkBuilder sets translation domain during parse, and unsets it again afterwards.
+    //In order for GtkBuilder to find the translations bindtextdomain has to be called
+    //for the domain. So here on the first setting of "domain" we call Translate::Create
+    //to make sure that happens. Without this, if some other part of LibreOffice has
+    //used the translation machinery for this domain it will still work, but if it
+    //hasn't, e.g. tdf#119929, then the translation fails
+    void translation_domain_set()
+    {
+        Translate::Create(gtk_builder_get_translation_domain(m_pBuilder), LanguageTag(m_aUILang));
+        g_signal_handler_disconnect(m_pBuilder, m_nNotifySignalId);
+    }
+
+    static void signalNotify(GObject*, GParamSpec *pSpec, gpointer pData)
+    {
+        g_return_if_fail(pSpec != nullptr);
+        if (strcmp(pSpec->name, "translation-domain") == 0)
+        {
+            GtkInstanceBuilder* pBuilder = static_cast<GtkInstanceBuilder*>(pData);
+            pBuilder->translation_domain_set();
+        }
+    }
+
     static void postprocess(gpointer data, gpointer user_data)
     {
         GObject* pObject = static_cast<GObject*>(data);
@@ -5044,14 +5067,10 @@ public:
         , m_pStringReplace(Translate::GetReadStringHook())
         , m_sHelpRoot(rUIFile)
         , m_pParentWidget(pParent)
+        , m_nNotifySignalId(0)
     {
         ensure_intercept_drawing_area_accessibility();
 
-        OUString aUri(rUIRoot + rUIFile);
-        OUString aPath;
-        osl::FileBase::getSystemPathFromFileURL(aUri, aPath);
-        m_pBuilder = gtk_builder_new_from_file(OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).getStr());
-
         sal_Int32 nIdx = m_sHelpRoot.lastIndexOf('.');
         if (nIdx != -1)
             m_sHelpRoot = m_sHelpRoot.copy(0, nIdx);
@@ -5060,6 +5079,13 @@ public:
         m_aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
         m_aUILang = Application::GetSettings().GetUILanguageTag().getBcp47();
 
+        OUString aUri(rUIRoot + rUIFile);
+        OUString aPath;
+        osl::FileBase::getSystemPathFromFileURL(aUri, aPath);
+        m_pBuilder = gtk_builder_new();
+        m_nNotifySignalId = g_signal_connect_data(G_OBJECT(m_pBuilder), "notify", G_CALLBACK(signalNotify), this, nullptr, G_CONNECT_AFTER);
+        gtk_builder_add_from_file(m_pBuilder, OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).getStr(), nullptr);
+
         m_pObjectList = gtk_builder_get_objects(m_pBuilder);
         g_slist_foreach(m_pObjectList, postprocess, this);
 


More information about the Libreoffice-commits mailing list