[devhelp] init: init i18n in dh_init()



commit 3d6a03e179488771c2571d9819a5499045312b70
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun May 7 16:50:16 2017 +0200

    init: init i18n in dh_init()

 src/dh-init.c |   16 ++++++++++++++++
 src/dh-main.c |   14 +++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/src/dh-init.c b/src/dh-init.c
index 20bfaf1..10ba284 100644
--- a/src/dh-init.c
+++ b/src/dh-init.c
@@ -19,12 +19,28 @@
 
 #include "config.h"
 #include "dh-init.h"
+#include <glib/gi18n-lib.h>
 #include "dh-book-manager.h"
 #include "dh-settings.h"
 
+/**
+ * dh_init:
+ *
+ * Initializes the Devhelp library (e.g. for the internationalization).
+ *
+ * This function can be called several times, but is meant to be called at the
+ * beginning of main(), before any other Devhelp function call.
+ */
 void
 dh_init (void)
 {
+        static gboolean done = FALSE;
+
+        if (!done) {
+                bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+                bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+                done = TRUE;
+        }
 }
 
 /**
diff --git a/src/dh-main.c b/src/dh-main.c
index 4e75af7..d10e53c 100644
--- a/src/dh-main.c
+++ b/src/dh-main.c
@@ -20,7 +20,7 @@
 #include "config.h"
 
 #include <locale.h>
-#include <glib/gi18n-lib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 #include "devhelp.h"
@@ -29,20 +29,16 @@
 int
 main (int argc, char **argv)
 {
-        DhApp   *application;
-        gint     status;
+        DhApp *application;
+        gint status;
 
         setlocale (LC_ALL, "");
-        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
         textdomain (GETTEXT_PACKAGE);
 
-        /* Create new DhApp */
-        application = dh_app_new ();
+        dh_init ();
 
-        /* And run the GtkApplication */
+        application = dh_app_new ();
         status = g_application_run (G_APPLICATION (application), argc, argv);
-
         g_object_unref (application);
 
         dh_free_resources ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]