diff --git a/src/TransUtils.py b/src/TransUtils.py index 33209691d..f7d0f7781 100644 --- a/src/TransUtils.py +++ b/src/TransUtils.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2009 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,32 +26,31 @@ Provide translation assistance """ import gettext +import os +import const -localedir = '' -localedomain = 'gramps' +if "GRAMPSI18N" in os.environ: + LOCALEDIR = os.environ["GRAMPSI18N"] +elif os.path.exists( os.path.join(const.ROOT_DIR, "lang") ): + LOCALEDIR = os.path.join(const.ROOT_DIR, "lang") +else: + LOCALEDIR = os.path.join(const.PREFIXDIR, "share/locale") -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 +LOCALEDOMAIN = 'gramps' def setup_gettext(): - global localedir, localedomain - gettext.bindtextdomain(localedomain, localedir) - gettext.textdomain(localedomain) + """ + Setup the gettext environment. + + :returns: Nothing. + + """ + 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) + #gettext.install(LOCALEDOMAIN, LOCALEDIR, unicode=1) def sgettext(msgid, sep='|'): """ @@ -97,7 +97,7 @@ def sngettext(singular, plural, n, sep='|'): :rtype: unicode """ - msgval = gettext.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 dd9f432ca..e0269d4d9 100644 --- a/src/glade.py +++ b/src/glade.py @@ -80,7 +80,7 @@ class Glade(gtk.Builder): :returns: reference to the newly-created Glade instance """ gtk.Builder.__init__(self) - self.set_translation_domain(TransUtils.localedomain) + self.set_translation_domain(TransUtils.LOCALEDOMAIN) filename_given = filename is not None dirname_given = dirname is not None diff --git a/src/gramps.py b/src/gramps.py index 0fa5880d5..95a0e988b 100644 --- a/src/gramps.py +++ b/src/gramps.py @@ -42,20 +42,13 @@ LOG = logging.getLogger(".") # #------------------------------------------------------------------------- from Mime import mime_type_is_defined -from TransUtils import set_localedir, set_localedomain, setup_gettext +import TransUtils #------------------------------------------------------------------------- # # Load internationalization setup # #------------------------------------------------------------------------- -if "GRAMPSI18N" in os.environ: - loc = os.environ["GRAMPSI18N"] -elif os.path.exists( os.path.join(const.ROOT_DIR, "lang") ): - loc = os.path.join(const.ROOT_DIR, "lang") -else: - loc = os.path.join(const.PREFIXDIR, "share/locale") - try: locale.setlocale(locale.LC_ALL,'C') locale.setlocale(locale.LC_ALL,'') @@ -65,9 +58,7 @@ except ValueError: pass LOG.debug('Using locale:', locale.getlocale()) -set_localedir(loc) -set_localedomain("gramps") -setup_gettext() +TransUtils.setup_gettext() #------------------------------------------------------------------------- #