03090: All strings are not shown translated

svn: r12804
This commit is contained in:
Benny Malengier 2009-07-16 12:23:51 +00:00
parent cf506f544e
commit 67f912aa2d
3 changed files with 38 additions and 9 deletions

View File

@ -24,7 +24,33 @@
Provide translation assistance 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='|'): def sgettext(msgid, sep='|'):
""" """
@ -43,7 +69,7 @@ def sgettext(msgid, sep='|'):
:rtype: unicode :rtype: unicode
""" """
msgval = gettext(msgid) msgval = gettext.gettext(msgid)
if msgval == msgid: if msgval == msgid:
sep_idx = msgid.rfind(sep) sep_idx = msgid.rfind(sep)
msgval = msgid[sep_idx+1:] msgval = msgid[sep_idx+1:]
@ -71,7 +97,7 @@ def sngettext(singular, plural, n, sep='|'):
:rtype: unicode :rtype: unicode
""" """
msgval = ngettext(singular, plural,n) msgval = gettext.ngettext(singular, plural,n)
if msgval == singular: if msgval == singular:
sep_idx = singular.rfind(sep) sep_idx = singular.rfind(sep)
msgval = singular[sep_idx+1:] msgval = singular[sep_idx+1:]

View File

@ -48,6 +48,7 @@ import gtk
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import const import const
import TransUtils
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -79,6 +80,7 @@ class Glade(gtk.Builder):
:returns: reference to the newly-created Glade instance :returns: reference to the newly-created Glade instance
""" """
gtk.Builder.__init__(self) gtk.Builder.__init__(self)
self.set_translation_domain(TransUtils.localedomain)
filename_given = filename is not None filename_given = filename is not None
dirname_given = dirname is not None dirname_given = dirname is not None
@ -197,7 +199,6 @@ class Glade(gtk.Builder):
:rtype: object :rtype: object
:returns: child object :returns: child object
""" """
if not toplevel: if not toplevel:
toplevel = self.__toplevel toplevel = self.__toplevel
if not toplevel: if not toplevel:

View File

@ -42,6 +42,7 @@ LOG = logging.getLogger(".")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Mime import mime_type_is_defined 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: except ValueError:
pass pass
gettext.bindtextdomain("gramps",loc) LOG.debug('Using locale:', locale.getlocale())
gettext.textdomain("gramps") set_localedir(loc)
gettext.install("gramps",loc,unicode=1) set_localedomain("gramps")
setup_gettext()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #