From 67f912aa2df4e91cdd5b8718794638919804071e Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Thu, 16 Jul 2009 12:23:51 +0000 Subject: [PATCH] 03090: All strings are not shown translated svn: r12804 --- src/TransUtils.py | 32 +++++++++++++++++++++++++++++--- src/glade.py | 7 ++++--- src/gramps.py | 8 +++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/TransUtils.py b/src/TransUtils.py index 058d47af1..33209691d 100644 --- a/src/TransUtils.py +++ b/src/TransUtils.py @@ -24,7 +24,33 @@ Provide translation assistance """ -from gettext import (gettext, ngettext) +import gettext + +localedir = '' +localedomain = 'gramps' + +def set_localedir(dir): + """ + Set the directory where locale/gettext obtains translation files + """ + global localedir + localedir = dir + +def set_localedomain(name): + """ + Set the domain that locale/gettext should use + """ + global localedomain + localedomain = name + +def setup_gettext(): + global localedir, localedomain + gettext.bindtextdomain(localedomain, localedir) + gettext.textdomain(localedomain) + + #following installs _ as a python function, we avoid this as TransUtils is + #used sometimes: + #gettext.install(localedomain, localedir, unicode=1) def sgettext(msgid, sep='|'): """ @@ -43,7 +69,7 @@ def sgettext(msgid, sep='|'): :rtype: unicode """ - msgval = gettext(msgid) + msgval = gettext.gettext(msgid) if msgval == msgid: sep_idx = msgid.rfind(sep) msgval = msgid[sep_idx+1:] @@ -71,7 +97,7 @@ def sngettext(singular, plural, n, sep='|'): :rtype: unicode """ - msgval = ngettext(singular, plural,n) + msgval = gettext.ngettext(singular, plural,n) if msgval == singular: sep_idx = singular.rfind(sep) msgval = singular[sep_idx+1:] diff --git a/src/glade.py b/src/glade.py index d9088f29e..dd9f432ca 100644 --- a/src/glade.py +++ b/src/glade.py @@ -48,6 +48,7 @@ import gtk # #------------------------------------------------------------------------ import const +import TransUtils #------------------------------------------------------------------------ # @@ -77,9 +78,10 @@ class Glade(gtk.Builder): matching the file name. :rtype: object reference :returns: reference to the newly-created Glade instance - """ + """ gtk.Builder.__init__(self) - + self.set_translation_domain(TransUtils.localedomain) + filename_given = filename is not None dirname_given = dirname is not None @@ -197,7 +199,6 @@ class Glade(gtk.Builder): :rtype: object :returns: child object """ - if not toplevel: toplevel = self.__toplevel if not toplevel: diff --git a/src/gramps.py b/src/gramps.py index a92955b32..1093608ee 100644 --- a/src/gramps.py +++ b/src/gramps.py @@ -42,6 +42,7 @@ LOG = logging.getLogger(".") # #------------------------------------------------------------------------- from Mime import mime_type_is_defined +from TransUtils import set_localedir, set_localedomain, setup_gettext #------------------------------------------------------------------------- # @@ -63,9 +64,10 @@ except locale.Error: except ValueError: pass -gettext.bindtextdomain("gramps",loc) -gettext.textdomain("gramps") -gettext.install("gramps",loc,unicode=1) +LOG.debug('Using locale:', locale.getlocale()) +set_localedir(loc) +set_localedomain("gramps") +setup_gettext() #------------------------------------------------------------------------- #