comparison mercurial/i18n.py @ 7651:5b5036ef847a

i18n: encode output in user's local encoding This makes the translated output obey the HGENCODING environment variable or the preferred encoding as set by the LANG or LC_ALL environment variables. Python 2.4 has a lgettext method which is similar, except that it doesn't know about HGENCODING or the settings in .hgrc.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 15 Jan 2009 00:14:36 +0100
parents 85ae7aaf08e9
children de377b1a9a84
comparison
equal deleted inserted replaced
7650:85ae7aaf08e9 7651:5b5036ef847a
20 localedir = os.path.normpath(os.path.join(base, dir, 'locale')) 20 localedir = os.path.normpath(os.path.join(base, dir, 'locale'))
21 if os.path.isdir(localedir): 21 if os.path.isdir(localedir):
22 break 22 break
23 23
24 t = gettext.translation('hg', localedir, fallback=True) 24 t = gettext.translation('hg', localedir, fallback=True)
25 gettext = t.gettext 25
26 def gettext(message):
27 """Translate message.
28
29 The message is looked up in the catalog to get a Unicode string,
30 which is encoded in the local encoding before being returned.
31
32 Important: message is restricted to characters in the encoding
33 given by sys.getdefaultencoding() which is most likely 'ascii'.
34 """
35 # If message is None, t.ugettext will return u'None' as the
36 # translation whereas our callers expect us to return None.
37 if message is None:
38 return message
39
40 # We cannot just run the text through util.tolocal since that
41 # leads to infinite recursion when util._encoding is invalid.
42 try:
43 u = t.ugettext(message)
44 return u.encode(util._encoding, "replace")
45 except LookupError:
46 return message
47
26 _ = gettext 48 _ = gettext
49
50 # Moved after _ because of circular import.
51 import util