[Spice-devel] [spice-gtk] Initialise gettext library properly

Frediano Ziglio fziglio at redhat.com
Wed Aug 17 15:09:35 UTC 2016


This will allow internationalisation to work correctly.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 src/Makefile.am       |  3 +++
 src/spice-glib-main.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 src/spice-glib-main.c

diff --git a/src/Makefile.am b/src/Makefile.am
index fc84e30..53987dd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -104,6 +104,7 @@ SPICE_COMMON_CPPFLAGS =						\
 	$(NULL)
 
 AM_CPPFLAGS =					\
+	-DLOCALE_DIR=\""$(datadir)/locale"\"	\
 	$(SPICE_COMMON_CPPFLAGS)		\
 	$(SPICE_CFLAGS)				\
 	$(NULL)
@@ -276,6 +277,8 @@ libspice_client_glib_2_0_la_SOURCES =			\
 							\
 	client_sw_canvas.c	\
 	client_sw_canvas.h	\
+							\
+	spice-glib-main.c				\
 	$(NULL)
 
 nodist_libspice_client_glib_2_0_la_SOURCES =	\
diff --git a/src/spice-glib-main.c b/src/spice-glib-main.c
new file mode 100644
index 0000000..c2bd7ca
--- /dev/null
+++ b/src/spice-glib-main.c
@@ -0,0 +1,52 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2016 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <common/macros.h>
+
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
+
+BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+    if (fdwReason == DLL_PROCESS_ATTACH) {
+        char *basedir =
+            g_win32_get_package_installation_directory_of_module(hinstDLL);
+        char *localedir = g_build_filename(basedir, "share", "locale", NULL);
+        bindtextdomain(GETTEXT_PACKAGE, localedir);
+        g_free(localedir);
+        g_free(basedir);
+        bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+    }
+    return TRUE;
+}
+
+#else
+
+SPICE_CONSTRUCTOR_FUNC(i18n_init)
+{
+    bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+#endif
-- 
2.7.4



More information about the Spice-devel mailing list