From d01f7bf7df99e738e275c0f19beaf9ee8f4d39e0 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 3 Mar 2013 23:59:44 +0000 Subject: [PATCH] [r21540]GrampsLocale: Add _win_bindtextdomain Adapted from init_windows_gettext in Gramps3. Libintl-8.dll must be on the path, just like all of the other C-library dependencies. svn: r21543 --- gramps/gen/utils/grampslocale.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index 89876d7cd..e3077063b 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -145,6 +145,22 @@ class GrampsLocale(object): else: self.collation = os.environ["LC_COLLATE"] + def _win_bindtextdomain(self, localedomain, localedir): + """ + Help routine for loading and setting up libintl attributes + Returns libintl + """ + from ctypes import cdll + try: + libintl = cdll.LoadLibrary('libintl-8') + libintl.bindtextdomain(localedomain, + localedir.encode(sys.getfilesystemencoding())) + libintl.textdomain(localedomain) + libintl.bind_textdomain_codeset(localedomain, "UTF-8") + print("Set domain %s in %s" % (localedomain, localedir)) + except WindowsError: + LOG.warning("Localization library libintl not on %PATH%, localization will be incomplete") + def __init_first_instance(self, localedir=None, lang=None, domain=None, language=None): @@ -216,6 +232,8 @@ class GrampsLocale(object): # with locale instead of gettext. Win32 doesn't support bindtextdomain. if not win(): locale.bindtextdomain(self.localedomain, self.localedir) + else: + self._win_bindtextdomain(self.localedomain, self.localedir) self.initialized = True