1 '''
2 Provides support for the internationalization of SUE using the python gettext
3 module. Configures gettext to use the translation associated with the locale
4 set by the user's environment at runtime. If no appropriate translation is
5 found, the default language is used: the one in which the strings in the
6 code are written (i.e. English).
7
8 The gettext function in the gettext module is alised as _ to match the name of
9 the equivalent C function provided by GNU gettext tools.
10
11 See the Python documentation on the gettext module at
12 U{http://docs.python.org/lib/module-gettext.html}. A brief tutorial on
13 i18n and Python is available at
14 U{http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq22.002.htp}
15
16 @author: Peter Parente
17 @organization: IBM Corporation
18 @copyright: Copyright (c) 2005, 2007 IBM Corporation
19 @license: The BSD License
20
21 @author: Frank Zenker
22 @organization: IT Science Center Ruegen gGmbH, Germany
23 @copyright: Copyright (c) 2007, 2008 ITSC Ruegen
24 @license: The BSD License
25
26 All rights reserved. This program and the accompanying materials are made
27 available under the terms of the BSD license which accompanies
28 this distribution, and is available at
29 U{http://www.opensource.org/licenses/bsd-license.php}
30 '''
31 import locale, gettext, os.path
32 import gtk.glade
33
34 -def bind(domain, locale_dir):
35 '''
36 Convenience function for creating a new instance of a Python translation
37 class bound to a domain and locale directory other than the default one for
38 SUE. This function is useful in L{AEUserInterface}s which have translatable strings
39 and ship separately from SUE with their own translation files. For instance,
40 a L{AEScript <AEScript.AEScript>} writer may call this function globally in his L{AEScript <AEScript.AEScript>} and assign
41 the result to a global variable _ to use the GNU translation system without
42 affecting how other components of SUE are translated.
43
44 @param domain: Filename of the translation file, typically the name of the
45 project with which it is associated
46 @type domain: string
47 @param locale_dir: Directory to search for translation files for the domain
48 @type locale_dir: string
49 @return: Bound method ugettext on the translation object
50 @rtype: callable
51 '''
52 try:
53 t = gettext.translation(domain, locale_dir)
54 return t.ugettext
55 except IOError:
56
57
58 return lambda x: unicode(x)
59
60
61 locale.setlocale(locale.LC_ALL, '')
62
63 LOCALE_DIR = os.path.join('/usr/local', 'share', 'locale')
64 DOMAIN = 'sue'
65
66 gtk.glade.bindtextdomain(DOMAIN, LOCALE_DIR)
67 gtk.glade.textdomain(DOMAIN)
68
69 _ = bind(DOMAIN, LOCALE_DIR)
70