[evince/gnome-2-30] [windows] Fix localization on Windows



commit d09ccb5042f008462c2ee3d967ec9db15083bc8c
Author: Hib Eris <hib hiberis nl>
Date:   Mon May 17 11:38:16 2010 +0200

    [windows] Fix localization on Windows
    
    Fixes bgo#610548

 libdocument/ev-init.c    |   55 +++++++++++++++++++++++++++++++++++++++++++++-
 previewer/ev-previewer.c |   31 +++++++++++++++++++++++++-
 shell/main.c             |   31 +++++++++++++++++++++++++-
 3 files changed, 114 insertions(+), 3 deletions(-)
---
diff --git a/libdocument/ev-init.c b/libdocument/ev-init.c
index 2b247eb..fb10ac5 100644
--- a/libdocument/ev-init.c
+++ b/libdocument/ev-init.c
@@ -21,6 +21,9 @@
 
 #include <glib.h>
 #include <glib/gi18n-lib.h>
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
 
 #include "ev-init.h"
 #include "ev-backends-manager.h"
@@ -29,6 +32,54 @@
 
 static int ev_init_count;
 
+#ifdef G_OS_WIN32
+
+static HMODULE evdocument_dll = NULL;
+
+#ifdef DLL_EXPORT
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+	 DWORD     fdwReason,
+	 LPVOID    lpvReserved)
+{
+	if (fdwReason == DLL_PROCESS_ATTACH)
+		evdocument_dll = hinstDLL;
+
+	return TRUE;
+}
+#endif
+
+#endif
+
+static gchar *
+_ev_get_locale_dir (void)
+{
+#ifdef G_OS_WIN32
+	gchar *install_dir = NULL, *locale_dir;
+	gchar *retval = NULL;
+
+	if (evdocument_dll != NULL)
+		install_dir = g_win32_get_package_installation_directory_of_module (evdocument_dll);
+
+	if (install_dir) {
+		locale_dir = g_build_filename (install_dir,
+			"share", "locale", NULL);
+
+		retval = g_win32_locale_filename_from_utf8 (locale_dir);
+
+		g_free (install_dir);
+		g_free (locale_dir);
+	}
+
+	if (retval)
+		return retval;
+	else
+		return g_strdup ("");
+#else
+	return g_strdup (GNOMELOCALEDIR);
+#endif
+}
+
 /**
  * ev_init:
  *
@@ -49,7 +100,9 @@ ev_init (void)
                 return have_backends;
 
 	/* set up translation catalog */
-	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+	gchar *tmp = _ev_get_locale_dir ();
+	bindtextdomain (GETTEXT_PACKAGE, tmp);
+	g_free (tmp);
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
         _ev_debug_init ();
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
index 990a003..14d4f2f 100644
--- a/previewer/ev-previewer.c
+++ b/previewer/ev-previewer.c
@@ -100,6 +100,33 @@ ev_previewer_load_document (const gchar     *filename,
 	g_free (uri);
 }
 
+static gchar*
+ev_previewer_get_locale_dir ()
+{
+#ifdef G_OS_WIN32
+	gchar *install_dir = NULL, *locale_dir;
+	gchar *retval = NULL;
+
+	install_dir =
+	    g_win32_get_package_installation_directory_of_module (NULL);
+
+	if (install_dir) {
+		locale_dir = g_build_filename (install_dir,
+					"share", "locale", NULL);
+		retval = g_win32_locale_filename_from_utf8 (locale_dir);
+		g_free (install_dir);
+		g_free (locale_dir);
+	}
+
+	if (retval)
+		return retval;
+	else
+		return g_strdup ("");
+#else
+	return g_strdup (GNOMELOCALEDIR);
+#endif
+}
+
 gint
 main (gint argc, gchar **argv)
 {
@@ -139,7 +166,9 @@ main (gint argc, gchar **argv)
 
 #ifdef ENABLE_NLS
 	/* Initialize the i18n stuff */
-	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+	gchar *tmp = ev_previewer_get_locale_dir ();
+	bindtextdomain (GETTEXT_PACKAGE, tmp);
+	g_free (tmp);
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 #endif
diff --git a/shell/main.c b/shell/main.c
index 620cba4..54507ee 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -227,6 +227,33 @@ load_files (const char **files)
         }
 }
 
+static gchar*
+ev_get_locale_dir ()
+{
+#ifdef G_OS_WIN32
+	gchar *install_dir = NULL, *locale_dir;
+	gchar *retval = NULL;
+
+	install_dir =
+	    g_win32_get_package_installation_directory_of_module (NULL);
+
+	if (install_dir) {
+		locale_dir = g_build_filename (install_dir,
+					"share", "locale", NULL);
+		retval = g_win32_locale_filename_from_utf8 (locale_dir);
+		g_free (install_dir);
+		g_free (locale_dir);
+	}
+
+	if (retval)
+		return retval;
+	else
+		return g_strdup ("");
+#else
+	return g_strdup (GNOMELOCALEDIR);
+#endif
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -264,7 +291,9 @@ main (int argc, char *argv[])
 
 #ifdef ENABLE_NLS
 	/* Initialize the i18n stuff */
-	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+	gchar *tmp = ev_get_locale_dir ();
+	bindtextdomain (GETTEXT_PACKAGE, tmp);
+	g_free (tmp);
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 #endif



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