[libpeas/msvc: 8/12] Python Loader: Do not hardcode localedir on Windows



commit e45b36957a8f9902409b11a5e951cf45789ccf8e
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Oct 15 14:46:38 2018 +0800

    Python Loader: Do not hardcode localedir on Windows
    
    We construct them dynamically according to the path that the libpeas DLL
    is in, so that they can be relocated easily on Windows, which is often
    the case there.

 loaders/python/peas-python-internal.c  | 12 +++++++++++-
 loaders/python/peas-python-internal.py |  7 ++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/loaders/python/peas-python-internal.c b/loaders/python/peas-python-internal.c
index 5889188..4646c3c 100644
--- a/loaders/python/peas-python-internal.c
+++ b/loaders/python/peas-python-internal.c
@@ -68,6 +68,15 @@ peas_python_internal_setup (gboolean already_initialized)
   PyObject *builtins_module, *globals, *result;
   PyObject *code = NULL, *failed_method = NULL;
   gboolean success = FALSE;
+  char *localedir = NULL;
+
+#ifdef G_OS_WIN32
+  char *basedir = g_win32_get_package_installation_directory_of_module (NULL);
+  localedir = g_build_filename (basedir, "share", "locale", NULL);
+  g_free (basedir);
+#else
+  localedir = g_strdup (PEAS_LOCALEDIR);
+#endif
 
 #define goto_error_if_failed(cond) \
   G_STMT_START { \
@@ -129,8 +138,9 @@ peas_python_internal_setup (gboolean already_initialized)
   goto_error_if_failed (PyModule_AddStringMacro (internal_module,
                                                  GETTEXT_PACKAGE) == 0);
   goto_error_if_failed (PyModule_AddStringMacro (internal_module,
-                                                 PEAS_LOCALEDIR) == 0);
+                                                 localedir) == 0);
 
+  g_free (localedir);
   globals = PyModule_GetDict (internal_module);
   result = PyEval_EvalCode ((gpointer) code, globals, globals);
   Py_XDECREF (result);
diff --git a/loaders/python/peas-python-internal.py b/loaders/python/peas-python-internal.py
index 1a0a745..86360b3 100644
--- a/loaders/python/peas-python-internal.py
+++ b/loaders/python/peas-python-internal.py
@@ -43,7 +43,12 @@ class Hooks(object):
 
         sys.argv = [PRGNAME]
 
-        gettext.install(GETTEXT_PACKAGE, PEAS_LOCALEDIR)
+        if os.name == 'nt':
+            basedir = GLib.win32_get_package_installation_directory_of_module(None)
+            peas_locale_dir = os.path.join (basedir, 'share', 'locale')
+            gettext.install(GETTEXT_PACKAGE, peas_locale_dir)
+        else:
+            gettext.install(GETTEXT_PACKAGE, PEAS_LOCALEDIR)
 
         self.__module_cache = {}
         self.__extension_cache = {}


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