Cleanup gettext configuration (in preparation for custom report translations).
svn: r13385
This commit is contained in:
parent
3266f85d46
commit
82a847226e
@ -2,6 +2,7 @@
|
|||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
# 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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -25,32 +26,31 @@ Provide translation assistance
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
import os
|
||||||
|
import const
|
||||||
|
|
||||||
localedir = ''
|
if "GRAMPSI18N" in os.environ:
|
||||||
localedomain = 'gramps'
|
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):
|
LOCALEDOMAIN = 'gramps'
|
||||||
"""
|
|
||||||
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():
|
def setup_gettext():
|
||||||
global localedir, localedomain
|
"""
|
||||||
gettext.bindtextdomain(localedomain, localedir)
|
Setup the gettext environment.
|
||||||
gettext.textdomain(localedomain)
|
|
||||||
|
:returns: Nothing.
|
||||||
|
|
||||||
|
"""
|
||||||
|
gettext.bindtextdomain(LOCALEDOMAIN, LOCALEDIR)
|
||||||
|
gettext.textdomain(LOCALEDOMAIN)
|
||||||
|
|
||||||
#following installs _ as a python function, we avoid this as TransUtils is
|
#following installs _ as a python function, we avoid this as TransUtils is
|
||||||
#used sometimes:
|
#used sometimes:
|
||||||
#gettext.install(localedomain, localedir, unicode=1)
|
#gettext.install(LOCALEDOMAIN, LOCALEDIR, unicode=1)
|
||||||
|
|
||||||
def sgettext(msgid, sep='|'):
|
def sgettext(msgid, sep='|'):
|
||||||
"""
|
"""
|
||||||
@ -97,7 +97,7 @@ def sngettext(singular, plural, n, sep='|'):
|
|||||||
:rtype: unicode
|
:rtype: unicode
|
||||||
|
|
||||||
"""
|
"""
|
||||||
msgval = gettext.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:]
|
||||||
|
@ -80,7 +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)
|
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
|
||||||
|
@ -42,20 +42,13 @@ 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
|
import TransUtils
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Load internationalization setup
|
# 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:
|
try:
|
||||||
locale.setlocale(locale.LC_ALL,'C')
|
locale.setlocale(locale.LC_ALL,'C')
|
||||||
locale.setlocale(locale.LC_ALL,'')
|
locale.setlocale(locale.LC_ALL,'')
|
||||||
@ -65,9 +58,7 @@ except ValueError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
LOG.debug('Using locale:', locale.getlocale())
|
LOG.debug('Using locale:', locale.getlocale())
|
||||||
set_localedir(loc)
|
TransUtils.setup_gettext()
|
||||||
set_localedomain("gramps")
|
|
||||||
setup_gettext()
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user