Cleanup gettext configuration (in preparation for custom report translations).

svn: r13385
This commit is contained in:
Brian Matherly 2009-10-18 22:18:29 +00:00
parent 3266f85d46
commit 82a847226e
3 changed files with 23 additions and 32 deletions

View File

@ -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='|'):
"""

View File

@ -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

View File

@ -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()
#-------------------------------------------------------------------------
#