From 694f75746302c6f6cc1b656011e46bfa127b6eba Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 3 Mar 2013 23:40:27 +0000 Subject: [PATCH] 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: r21540 --- 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 ecd4f5c75..1e37db0dc 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