FINALLY: this fixes translation issues with gtk.Builder on my box (ubuntu 9.10)

svn: r14253
This commit is contained in:
Benny Malengier 2010-02-06 17:17:20 +00:00
parent f7aad51665
commit e752af9ed6
3 changed files with 45 additions and 3 deletions

9
README
View File

@ -10,6 +10,15 @@ The following packages *MUST* be installed in order for Gramps to work:
librsvg2 (svg icon view) librsvg2 (svg icon view)
xdg-utils xdg-utils
The following package is needed for full translation of the interface
to your language:
language-pack-gnome-xx
Translation of GTK elements to your language, with
with xx your language code eg for Dutch you need
language-pack-gnome-nl. The translation of the
Gramps strings is included with the source code.
The following packages are *STRONGLY RECOMMENDED* to be installed: The following packages are *STRONGLY RECOMMENDED* to be installed:
GraphViz Enable creation of graphs using GraphViz engine GraphViz Enable creation of graphs using GraphViz engine
http://www.graphviz.org http://www.graphviz.org

View File

@ -33,6 +33,7 @@ Provide translation assistance
import gettext import gettext
import sys import sys
import os import os
import locale
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -69,11 +70,27 @@ def setup_gettext():
""" """
gettext.bindtextdomain(LOCALEDOMAIN, LOCALEDIR) gettext.bindtextdomain(LOCALEDOMAIN, LOCALEDIR)
gettext.textdomain(LOCALEDOMAIN) gettext.textdomain(LOCALEDOMAIN)
try:
locale.bindtextdomain(LOCALEDOMAIN, LOCALEDIR)
except ValueError:
print 'Failed to bind text domain, gtk.Builder() has no translation'
#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 setup_windows_gtk():
""" function to decide if needed on windows
This function should be called on windows instead of locale.bindtextdomain
"""
from Utils import win
if win():
try:
libintl = ctypes.cdll.LoadLibrary("C:\\GTK\\gtk-2.18.5\\bin\\intl.dll")
libintl.bindtextdomain(LOCALEDOMAIN, LOCALEDIR)
except:
print "Error Loading translations into gtk.builder files"
def get_localedomain(): def get_localedomain():
""" """
Get the LOCALEDOMAIN used for the Gramps application. Get the LOCALEDOMAIN used for the Gramps application.

View File

@ -28,11 +28,11 @@
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import sys import sys
import os import os
import locale
import const import const
import signal import signal
import gettext import gettext
_ = gettext.gettext _ = gettext.gettext
import locale
import logging import logging
LOG = logging.getLogger(".") LOG = logging.getLogger(".")
@ -50,6 +50,12 @@ import TransUtils
# Load internationalization setup # Load internationalization setup
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
#the order in which bindtextdomain on gettext and on locale is called
#appears important, so we refrain from doing first all gettext.
#
#TransUtils.setup_gettext()
gettext.bindtextdomain(TransUtils.LOCALEDOMAIN, TransUtils.LOCALEDIR)
try: try:
locale.setlocale(locale.LC_ALL,'C') locale.setlocale(locale.LC_ALL,'C')
locale.setlocale(locale.LC_ALL,'') locale.setlocale(locale.LC_ALL,'')
@ -58,8 +64,18 @@ except locale.Error:
except ValueError: except ValueError:
pass pass
gettext.textdomain(TransUtils.LOCALEDOMAIN)
gettext.install(TransUtils.LOCALEDOMAIN, localedir=None, unicode=1) #None is sys default locale
try:
locale.bindtextdomain(TransUtils.LOCALEDOMAIN, TransUtils.LOCALEDIR)
#locale.textdomain(TransUtils.LOCALEDOMAIN)
except locale.Error:
print 'No translation in some gtk.Builder strings, '\
'call TransUtils.setup_windows_gtk ??'
LOG.debug('Using locale:', locale.getlocale()) LOG.debug('Using locale:', locale.getlocale())
TransUtils.setup_gettext()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #