/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/__init__.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/__init__.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1871 - (hide annotations)
Mon Oct 27 17:11:06 2003 UTC (21 years, 4 months ago) by bh
Original Path: trunk/thuban/Thuban/__init__.py
File MIME type: text/x-python
File size: 3178 byte(s)
Rework how localization works so that we use wx's translation
functions when running Thuban as a normal application but not when
we don't need any UI, such as in the test suite. See the comment
in Thuban/__init__.py for details

* Thuban/__init__.py (_): Add one level of indirection to make the
translation handling more flexible and to make it possible to use
either wx's translation services or not.
(gettext_identity, translation_function_installed)
(install_translation_function): New function to help with this

* Thuban/UI/__init__.py: Install the wx specific translation
function if it's OK to do that

1 bh 671 # Copyright (c) 2001, 2003 by Intevation GmbH
2 bh 6 # Authors:
3     # Bernhard Herzog <[email protected]>
4 jan 373 # Jan-Oliver Wagner <[email protected]>
5 bh 6 #
6     # This program is free software under the GPL (>=v2)
7     # Read the file COPYING coming with Thuban for details.
8 jan 373
9 bh 671 import os
10    
11 bh 1871 # Thuban Message Translation
12 bh 671 #
13 bh 1871 # This is somewhat tricky. On the one hand we want to use the wx
14     # facilities because that way the standard wx messages are also
15     # translated and we get automatic conversion of encodings so the we can
16     # use e.g. an UTF po/mo file in a Latin 1 environment. OTOH, we do not
17     # want to import the wxPython modules at all when running the test suite
18     # because otherwise the test suite would require a working X server
19     # connection.
20 bh 671 #
21 bh 1871 # Therefore this module only provides the hooks for installing the
22     # correct translation function with a default translation function that
23     # does nothing and simply returns the string it gets as argument.
24     #
25     # The front end to the installed translation function is _ (see it's
26     # doc-string).
27     #
28     # The Thuban.UI module is responsible for installing the wx translation
29     # function. It must take care to install the translation function as
30     # early as possible, i.e. when Thuban/UI/__init__.py is executed so that
31     # strings translated at module import time are translated (this also
32     # means that a program built on top of Thuban and which uses Thuban.UI
33     # should start by importing Thuban.UI before any other Thuban module.
34     #
35     # At the same time Thuban/UI/__init__.py should not import any wxPython
36     # module unless it really has to install the translation function, i.e.
37     # when no other translation function has already been installed. That
38     # way the test suite can override the wx translation by installing its
39     # own translation function before importing anything from Thuban.UI and
40     # actually before importing anything but the Thuban module itself.
41    
42     # Thedirectory holding the translation files (actually they're in
43     # language specific subdirectories of _message_dir)
44 bh 671 _message_dir = os.path.join(os.path.dirname(__file__), os.pardir, "Resources",
45     "Locale")
46    
47 bh 1871 def _(s):
48     """Return a localized version of the the string s
49 bh 671
50 bh 1871 This is the function to use in the sources to translate strings and
51     it simply delegates the translation to the installable translation
52     function. It's done this way so that _ may be imported with 'from
53     Thuban import _' even when the correct translation function hasn't
54     been installed yet.
55     """
56     return _translation_function(s)
57    
58     def gettext_identity(s):
59     """Default gettext implementation which returns the string as is"""
60     return s
61    
62     _translation_function = gettext_identity
63    
64     def translation_function_installed():
65     """Return whether a translation function has been installed."""
66     return _translation_function is not gettext_identity
67    
68     def install_translation_function(function):
69     """Install function as the translation function
70    
71     If a translation has already been installed that is not the default
72     implementation (gettext_identity) do nothing.
73     """
74     global _translation_function
75     if not translation_function_installed():
76     _translation_function = function

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26