blob: aa434098612504b756720da72e257926e389997e [file] [log] [blame]
Barry Warsaw95be23d2000-08-25 19:13:37 +00001"""Internationalization and localization support.
2
3This module provides internationalization (I18N) and localization (L10N)
4support for your Python programs by providing an interface to the GNU gettext
5message catalog library.
6
7I18N refers to the operation by which a program is made aware of multiple
8languages. L10N refers to the adaptation of your program, once
Barry Warsaw33d8d702000-08-30 03:29:58 +00009internationalized, to the local language and cultural habits.
Barry Warsaw95be23d2000-08-25 19:13:37 +000010
11"""
12
Barry Warsawfa488ec2000-08-25 20:26:43 +000013# This module represents the integration of work, contributions, feedback, and
14# suggestions from the following people:
Barry Warsaw95be23d2000-08-25 19:13:37 +000015#
16# Martin von Loewis, who wrote the initial implementation of the underlying
17# C-based libintlmodule (later renamed _gettext), along with a skeletal
18# gettext.py implementation.
19#
20# Peter Funk, who wrote fintl.py, a fairly complete wrapper around intlmodule,
21# which also included a pure-Python implementation to read .mo files if
22# intlmodule wasn't available.
23#
24# James Henstridge, who also wrote a gettext.py module, which has some
25# interesting, but currently unsupported experimental features: the notion of
26# a Catalog class and instances, and the ability to add to a catalog file via
27# a Python API.
28#
29# Barry Warsaw integrated these modules, wrote the .install() API and code,
30# and conformed all C and Python code to Python's coding standards.
Barry Warsaw33d8d702000-08-30 03:29:58 +000031#
32# Francois Pinard and Marc-Andre Lemburg also contributed valuably to this
33# module.
34#
Martin v. Löwisa57dccd2003-03-10 16:01:43 +000035# J. David Ibanez implemented plural forms. Bruno Haible fixed some bugs.
Martin v. Löwisd8996052002-11-21 21:45:32 +000036#
Barry Warsaw33d8d702000-08-30 03:29:58 +000037# TODO:
38# - Lazy loading of .mo files. Currently the entire catalog is loaded into
39# memory, but that's probably bad for large translated programs. Instead,
40# the lexical sort of original strings in GNU .mo files should be exploited
41# to do binary searches and lazy initializations. Or you might want to use
42# the undocumented double-hash algorithm for .mo files with hash tables, but
43# you'll need to study the GNU gettext code to do this.
44#
45# - Support Solaris .mo file formats. Unfortunately, we've been unable to
46# find this format documented anywhere.
Barry Warsaw95be23d2000-08-25 19:13:37 +000047
Martin v. Löwisd8996052002-11-21 21:45:32 +000048
49import copy, os, re, struct, sys
Barry Warsaw33d8d702000-08-30 03:29:58 +000050from errno import ENOENT
Barry Warsaw95be23d2000-08-25 19:13:37 +000051
Martin v. Löwisd8996052002-11-21 21:45:32 +000052
Barry Warsawa1ce93f2003-04-11 18:36:43 +000053__all__ = ['NullTranslations', 'GNUTranslations', 'Catalog',
54 'find', 'translation', 'install', 'textdomain', 'bindtextdomain',
55 'dgettext', 'dngettext', 'gettext', 'ngettext',
56 ]
Skip Montanaro2dd42762001-01-23 15:35:05 +000057
Barry Warsaw33d8d702000-08-30 03:29:58 +000058_default_localedir = os.path.join(sys.prefix, 'share', 'locale')
Barry Warsaw95be23d2000-08-25 19:13:37 +000059
60
Martin v. Löwisd8996052002-11-21 21:45:32 +000061def test(condition, true, false):
62 """
63 Implements the C expression:
64
65 condition ? true : false
66
67 Required to correctly interpret plural forms.
68 """
69 if condition:
70 return true
71 else:
72 return false
73
74
75def c2py(plural):
76 """
77 Gets a C expression as used in PO files for plural forms and
78 returns a Python lambda function that implements an equivalent
79 expression.
80 """
81 # Security check, allow only the "n" identifier
82 from StringIO import StringIO
83 import token, tokenize
84 tokens = tokenize.generate_tokens(StringIO(plural).readline)
Martin v. Löwisa57dccd2003-03-10 16:01:43 +000085 try:
86 danger = [ x for x in tokens if x[0] == token.NAME and x[1] != 'n' ]
87 except tokenize.TokenError:
88 raise ValueError, \
89 'plural forms expression error, maybe unbalanced parenthesis'
90 else:
91 if danger:
92 raise ValueError, 'plural forms expression could be dangerous'
Martin v. Löwisd8996052002-11-21 21:45:32 +000093
94 # Replace some C operators by their Python equivalents
95 plural = plural.replace('&&', ' and ')
96 plural = plural.replace('||', ' or ')
97
Martin v. Löwisa57dccd2003-03-10 16:01:43 +000098 expr = re.compile(r'\!([^=])')
99 plural = expr.sub(' not \\1', plural)
Martin v. Löwisd8996052002-11-21 21:45:32 +0000100
101 # Regular expression and replacement function used to transform
102 # "a?b:c" to "test(a,b,c)".
103 expr = re.compile(r'(.*?)\?(.*?):(.*)')
104 def repl(x):
105 return "test(%s, %s, %s)" % (x.group(1), x.group(2),
106 expr.sub(repl, x.group(3)))
107
108 # Code to transform the plural expression, taking care of parentheses
109 stack = ['']
110 for c in plural:
111 if c == '(':
112 stack.append('')
113 elif c == ')':
Martin v. Löwisa57dccd2003-03-10 16:01:43 +0000114 if len(stack) == 1:
115 # Actually, we never reach this code, because unbalanced
116 # parentheses get caught in the security check at the
117 # beginning.
Martin v. Löwisd8996052002-11-21 21:45:32 +0000118 raise ValueError, 'unbalanced parenthesis in plural form'
119 s = expr.sub(repl, stack.pop())
120 stack[-1] += '(%s)' % s
121 else:
122 stack[-1] += c
123 plural = expr.sub(repl, stack.pop())
124
125 return eval('lambda n: int(%s)' % plural)
126
127
Tim Peters07e99cb2001-01-14 23:47:14 +0000128
Barry Warsawfa488ec2000-08-25 20:26:43 +0000129def _expand_lang(locale):
130 from locale import normalize
131 locale = normalize(locale)
132 COMPONENT_CODESET = 1 << 0
133 COMPONENT_TERRITORY = 1 << 1
134 COMPONENT_MODIFIER = 1 << 2
135 # split up the locale into its base components
136 mask = 0
137 pos = locale.find('@')
138 if pos >= 0:
139 modifier = locale[pos:]
140 locale = locale[:pos]
141 mask |= COMPONENT_MODIFIER
142 else:
143 modifier = ''
144 pos = locale.find('.')
145 if pos >= 0:
146 codeset = locale[pos:]
147 locale = locale[:pos]
148 mask |= COMPONENT_CODESET
149 else:
150 codeset = ''
151 pos = locale.find('_')
152 if pos >= 0:
153 territory = locale[pos:]
154 locale = locale[:pos]
155 mask |= COMPONENT_TERRITORY
156 else:
157 territory = ''
158 language = locale
159 ret = []
160 for i in range(mask+1):
161 if not (i & ~mask): # if all components for this combo exist ...
162 val = language
163 if i & COMPONENT_TERRITORY: val += territory
164 if i & COMPONENT_CODESET: val += codeset
165 if i & COMPONENT_MODIFIER: val += modifier
166 ret.append(val)
167 ret.reverse()
168 return ret
169
170
Tim Peters07e99cb2001-01-14 23:47:14 +0000171
Barry Warsaw33d8d702000-08-30 03:29:58 +0000172class NullTranslations:
173 def __init__(self, fp=None):
174 self._info = {}
Barry Warsaw6008cbd2003-04-11 20:26:47 +0000175 self._charset = None
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000176 self._fallback = None
Raymond Hettinger094662a2002-06-01 01:29:16 +0000177 if fp is not None:
Barry Warsaw33d8d702000-08-30 03:29:58 +0000178 self._parse(fp)
Barry Warsaw95be23d2000-08-25 19:13:37 +0000179
Barry Warsaw33d8d702000-08-30 03:29:58 +0000180 def _parse(self, fp):
181 pass
182
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000183 def add_fallback(self, fallback):
184 if self._fallback:
185 self._fallback.add_fallback(fallback)
186 else:
187 self._fallback = fallback
188
Barry Warsaw33d8d702000-08-30 03:29:58 +0000189 def gettext(self, message):
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000190 if self._fallback:
191 return self._fallback.gettext(message)
Barry Warsaw33d8d702000-08-30 03:29:58 +0000192 return message
193
Martin v. Löwisd8996052002-11-21 21:45:32 +0000194 def ngettext(self, msgid1, msgid2, n):
195 if self._fallback:
196 return self._fallback.ngettext(msgid1, msgid2, n)
197 if n == 1:
198 return msgid1
199 else:
200 return msgid2
201
Barry Warsaw33d8d702000-08-30 03:29:58 +0000202 def ugettext(self, message):
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000203 if self._fallback:
204 return self._fallback.ugettext(message)
Barry Warsaw33d8d702000-08-30 03:29:58 +0000205 return unicode(message)
206
Martin v. Löwisd8996052002-11-21 21:45:32 +0000207 def ungettext(self, msgid1, msgid2, n):
208 if self._fallback:
209 return self._fallback.ungettext(msgid1, msgid2, n)
210 if n == 1:
211 return unicode(msgid1)
212 else:
213 return unicode(msgid2)
214
Barry Warsaw33d8d702000-08-30 03:29:58 +0000215 def info(self):
216 return self._info
217
218 def charset(self):
219 return self._charset
220
221 def install(self, unicode=0):
222 import __builtin__
223 __builtin__.__dict__['_'] = unicode and self.ugettext or self.gettext
224
225
226class GNUTranslations(NullTranslations):
227 # Magic number of .mo files
Barry Warsaw09707e32002-08-14 15:09:12 +0000228 LE_MAGIC = 0x950412deL
229 BE_MAGIC = 0xde120495L
Barry Warsaw95be23d2000-08-25 19:13:37 +0000230
Barry Warsawa1ce93f2003-04-11 18:36:43 +0000231 def __init__(self, fp=None, coerce=False):
232 # Set this attribute before calling the base class constructor, since
233 # the latter calls _parse() which depends on self._coerce.
234 self._coerce = coerce
235 NullTranslations.__init__(self, fp)
236
Barry Warsaw95be23d2000-08-25 19:13:37 +0000237 def _parse(self, fp):
238 """Override this method to support alternative .mo formats."""
239 unpack = struct.unpack
240 filename = getattr(fp, 'name', '')
241 # Parse the .mo file header, which consists of 5 little endian 32
242 # bit words.
Barry Warsaw33d8d702000-08-30 03:29:58 +0000243 self._catalog = catalog = {}
Martin v. Löwisa57dccd2003-03-10 16:01:43 +0000244 self.plural = lambda n: int(n != 1) # germanic plural by default
Barry Warsaw95be23d2000-08-25 19:13:37 +0000245 buf = fp.read()
Barry Warsaw9a2d9d72000-08-31 23:28:52 +0000246 buflen = len(buf)
Barry Warsaw33d8d702000-08-30 03:29:58 +0000247 # Are we big endian or little endian?
Barry Warsaw09707e32002-08-14 15:09:12 +0000248 magic = unpack('<I', buf[:4])[0]
Barry Warsaw33d8d702000-08-30 03:29:58 +0000249 if magic == self.LE_MAGIC:
Barry Warsaw09707e32002-08-14 15:09:12 +0000250 version, msgcount, masteridx, transidx = unpack('<4I', buf[4:20])
251 ii = '<II'
Barry Warsaw33d8d702000-08-30 03:29:58 +0000252 elif magic == self.BE_MAGIC:
Barry Warsaw09707e32002-08-14 15:09:12 +0000253 version, msgcount, masteridx, transidx = unpack('>4I', buf[4:20])
254 ii = '>II'
Barry Warsaw33d8d702000-08-30 03:29:58 +0000255 else:
Barry Warsaw95be23d2000-08-25 19:13:37 +0000256 raise IOError(0, 'Bad magic number', filename)
Barry Warsaw95be23d2000-08-25 19:13:37 +0000257 # Now put all messages from the .mo file buffer into the catalog
258 # dictionary.
259 for i in xrange(0, msgcount):
Barry Warsaw33d8d702000-08-30 03:29:58 +0000260 mlen, moff = unpack(ii, buf[masteridx:masteridx+8])
Barry Warsaw09707e32002-08-14 15:09:12 +0000261 mend = moff + mlen
Barry Warsaw33d8d702000-08-30 03:29:58 +0000262 tlen, toff = unpack(ii, buf[transidx:transidx+8])
Barry Warsaw09707e32002-08-14 15:09:12 +0000263 tend = toff + tlen
Barry Warsaw9a2d9d72000-08-31 23:28:52 +0000264 if mend < buflen and tend < buflen:
Martin v. Löwisd8996052002-11-21 21:45:32 +0000265 msg = buf[moff:mend]
Barry Warsaw33d8d702000-08-30 03:29:58 +0000266 tmsg = buf[toff:tend]
Barry Warsaw95be23d2000-08-25 19:13:37 +0000267 else:
268 raise IOError(0, 'File is corrupt', filename)
Barry Warsaw33d8d702000-08-30 03:29:58 +0000269 # See if we're looking at GNU .mo conventions for metadata
Barry Warsaw6008cbd2003-04-11 20:26:47 +0000270 if mlen == 0:
Barry Warsaw33d8d702000-08-30 03:29:58 +0000271 # Catalog description
Barry Warsawa1ce93f2003-04-11 18:36:43 +0000272 for item in tmsg.splitlines():
Barry Warsaw33d8d702000-08-30 03:29:58 +0000273 item = item.strip()
274 if not item:
275 continue
276 k, v = item.split(':', 1)
277 k = k.strip().lower()
278 v = v.strip()
279 self._info[k] = v
280 if k == 'content-type':
281 self._charset = v.split('charset=')[1]
Martin v. Löwisd8996052002-11-21 21:45:32 +0000282 elif k == 'plural-forms':
283 v = v.split(';')
284## nplurals = v[0].split('nplurals=')[1]
285## nplurals = int(nplurals.strip())
286 plural = v[1].split('plural=')[1]
287 self.plural = c2py(plural)
Barry Warsaw6008cbd2003-04-11 20:26:47 +0000288 if msg.find('\x00') >= 0:
289 # Plural forms
290 msgid1, msgid2 = msg.split('\x00')
291 tmsg = tmsg.split('\x00')
292 if self._coerce:
293 msgid1 = unicode(msgid1, self._charset)
294 tmsg = [unicode(x, self._charset) for x in tmsg]
295 for i in range(len(tmsg)):
296 catalog[(msgid1, i)] = tmsg[i]
297 else:
298 if self._coerce:
299 msg = unicode(msg, self._charset)
300 tmsg = unicode(tmsg, self._charset)
301 catalog[msg] = tmsg
Barry Warsaw95be23d2000-08-25 19:13:37 +0000302 # advance to next entry in the seek tables
Barry Warsawfa488ec2000-08-25 20:26:43 +0000303 masteridx += 8
304 transidx += 8
Barry Warsaw33d8d702000-08-30 03:29:58 +0000305
306 def gettext(self, message):
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000307 try:
308 return self._catalog[message]
309 except KeyError:
310 if self._fallback:
311 return self._fallback.gettext(message)
312 return message
Barry Warsaw33d8d702000-08-30 03:29:58 +0000313
Martin v. Löwisd8996052002-11-21 21:45:32 +0000314 def ngettext(self, msgid1, msgid2, n):
315 try:
316 return self._catalog[(msgid1, self.plural(n))]
317 except KeyError:
318 if self._fallback:
319 return self._fallback.ngettext(msgid1, msgid2, n)
320 if n == 1:
321 return msgid1
322 else:
323 return msgid2
324
Barry Warsaw33d8d702000-08-30 03:29:58 +0000325 def ugettext(self, message):
Barry Warsawa1ce93f2003-04-11 18:36:43 +0000326 missing = object()
327 tmsg = self._catalog.get(message, missing)
328 if tmsg is missing:
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000329 if self._fallback:
330 return self._fallback.ugettext(message)
331 tmsg = message
Barry Warsawa1ce93f2003-04-11 18:36:43 +0000332 if not self._coerce:
333 return unicode(tmsg, self._charset)
334 # The msgstr is already coerced to Unicode
335 return tmsg
Barry Warsaw95be23d2000-08-25 19:13:37 +0000336
Martin v. Löwisd8996052002-11-21 21:45:32 +0000337 def ungettext(self, msgid1, msgid2, n):
338 try:
339 tmsg = self._catalog[(msgid1, self.plural(n))]
340 except KeyError:
341 if self._fallback:
342 return self._fallback.ungettext(msgid1, msgid2, n)
343 if n == 1:
344 tmsg = msgid1
345 else:
346 tmsg = msgid2
Barry Warsawa1ce93f2003-04-11 18:36:43 +0000347 if not self._coerce:
348 return unicode(tmsg, self._charset)
349 # The msgstr is already coerced to Unicode
350 return tmsg
Martin v. Löwisd8996052002-11-21 21:45:32 +0000351
Tim Peters07e99cb2001-01-14 23:47:14 +0000352
Barry Warsaw95be23d2000-08-25 19:13:37 +0000353# Locate a .mo file using the gettext strategy
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000354def find(domain, localedir=None, languages=None, all=0):
Barry Warsaw95be23d2000-08-25 19:13:37 +0000355 # Get some reasonable defaults for arguments that were not supplied
Barry Warsaw95be23d2000-08-25 19:13:37 +0000356 if localedir is None:
Barry Warsaw33d8d702000-08-30 03:29:58 +0000357 localedir = _default_localedir
Barry Warsaw95be23d2000-08-25 19:13:37 +0000358 if languages is None:
359 languages = []
360 for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
361 val = os.environ.get(envar)
362 if val:
363 languages = val.split(':')
364 break
365 if 'C' not in languages:
366 languages.append('C')
Barry Warsawfa488ec2000-08-25 20:26:43 +0000367 # now normalize and expand the languages
Barry Warsaw75f81012000-10-16 15:47:50 +0000368 nelangs = []
Barry Warsawfa488ec2000-08-25 20:26:43 +0000369 for lang in languages:
370 for nelang in _expand_lang(lang):
Barry Warsaw75f81012000-10-16 15:47:50 +0000371 if nelang not in nelangs:
372 nelangs.append(nelang)
Barry Warsaw95be23d2000-08-25 19:13:37 +0000373 # select a language
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000374 if all:
375 result = []
376 else:
377 result = None
Barry Warsaw75f81012000-10-16 15:47:50 +0000378 for lang in nelangs:
Barry Warsaw95be23d2000-08-25 19:13:37 +0000379 if lang == 'C':
380 break
Barry Warsaw84314b72000-08-25 19:53:17 +0000381 mofile = os.path.join(localedir, lang, 'LC_MESSAGES', '%s.mo' % domain)
Barry Warsaw33d8d702000-08-30 03:29:58 +0000382 if os.path.exists(mofile):
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000383 if all:
384 result.append(mofile)
385 else:
386 return mofile
387 return result
Barry Warsaw95be23d2000-08-25 19:13:37 +0000388
389
Tim Peters07e99cb2001-01-14 23:47:14 +0000390
Barry Warsaw33d8d702000-08-30 03:29:58 +0000391# a mapping between absolute .mo file path and Translation object
392_translations = {}
393
Martin v. Löwis1be64192002-01-11 06:33:28 +0000394def translation(domain, localedir=None, languages=None,
395 class_=None, fallback=0):
Barry Warsaw33d8d702000-08-30 03:29:58 +0000396 if class_ is None:
397 class_ = GNUTranslations
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000398 mofiles = find(domain, localedir, languages, all=1)
399 if len(mofiles)==0:
Martin v. Löwis1be64192002-01-11 06:33:28 +0000400 if fallback:
401 return NullTranslations()
Barry Warsaw33d8d702000-08-30 03:29:58 +0000402 raise IOError(ENOENT, 'No translation file found for domain', domain)
Barry Warsaw33d8d702000-08-30 03:29:58 +0000403 # TBD: do we need to worry about the file pointer getting collected?
Barry Warsaw293b03f2000-10-05 18:48:12 +0000404 # Avoid opening, reading, and parsing the .mo file after it's been done
405 # once.
Martin v. Löwisa55ffae2002-01-11 06:58:49 +0000406 result = None
407 for mofile in mofiles:
408 key = os.path.abspath(mofile)
409 t = _translations.get(key)
410 if t is None:
411 t = _translations.setdefault(key, class_(open(mofile, 'rb')))
412 # Copy the translation object to allow setting fallbacks.
413 # All other instance data is shared with the cached object.
414 t = copy.copy(t)
415 if result is None:
416 result = t
417 else:
418 result.add_fallback(t)
419 return result
Barry Warsaw33d8d702000-08-30 03:29:58 +0000420
Tim Peters07e99cb2001-01-14 23:47:14 +0000421
Barry Warsaw33d8d702000-08-30 03:29:58 +0000422def install(domain, localedir=None, unicode=0):
Martin v. Löwis1be64192002-01-11 06:33:28 +0000423 translation(domain, localedir, fallback=1).install(unicode)
Barry Warsaw33d8d702000-08-30 03:29:58 +0000424
425
Tim Peters07e99cb2001-01-14 23:47:14 +0000426
Barry Warsaw33d8d702000-08-30 03:29:58 +0000427# a mapping b/w domains and locale directories
428_localedirs = {}
429# current global domain, `messages' used for compatibility w/ GNU gettext
430_current_domain = 'messages'
Barry Warsaw95be23d2000-08-25 19:13:37 +0000431
432
433def textdomain(domain=None):
Barry Warsaw95be23d2000-08-25 19:13:37 +0000434 global _current_domain
Barry Warsaw33d8d702000-08-30 03:29:58 +0000435 if domain is not None:
Barry Warsaw95be23d2000-08-25 19:13:37 +0000436 _current_domain = domain
Barry Warsaw33d8d702000-08-30 03:29:58 +0000437 return _current_domain
Barry Warsaw95be23d2000-08-25 19:13:37 +0000438
439
Barry Warsaw33d8d702000-08-30 03:29:58 +0000440def bindtextdomain(domain, localedir=None):
441 global _localedirs
442 if localedir is not None:
443 _localedirs[domain] = localedir
444 return _localedirs.get(domain, _default_localedir)
Barry Warsaw95be23d2000-08-25 19:13:37 +0000445
446
447def dgettext(domain, message):
Barry Warsaw33d8d702000-08-30 03:29:58 +0000448 try:
449 t = translation(domain, _localedirs.get(domain, None))
450 except IOError:
451 return message
452 return t.gettext(message)
Tim Peters07e99cb2001-01-14 23:47:14 +0000453
Barry Warsaw33d8d702000-08-30 03:29:58 +0000454
Martin v. Löwisd8996052002-11-21 21:45:32 +0000455def dngettext(domain, msgid1, msgid2, n):
456 try:
457 t = translation(domain, _localedirs.get(domain, None))
458 except IOError:
459 if n == 1:
460 return msgid1
461 else:
462 return msgid2
463 return t.ngettext(msgid1, msgid2, n)
464
465
Barry Warsaw33d8d702000-08-30 03:29:58 +0000466def gettext(message):
467 return dgettext(_current_domain, message)
Barry Warsaw95be23d2000-08-25 19:13:37 +0000468
469
Martin v. Löwisd8996052002-11-21 21:45:32 +0000470def ngettext(msgid1, msgid2, n):
471 return dngettext(_current_domain, msgid1, msgid2, n)
472
473
Barry Warsaw33d8d702000-08-30 03:29:58 +0000474# dcgettext() has been deemed unnecessary and is not implemented.
Barry Warsaw95be23d2000-08-25 19:13:37 +0000475
Barry Warsaw33d8d702000-08-30 03:29:58 +0000476# James Henstridge's Catalog constructor from GNOME gettext. Documented usage
477# was:
478#
479# import gettext
480# cat = gettext.Catalog(PACKAGE, localedir=LOCALEDIR)
481# _ = cat.gettext
482# print _('Hello World')
Barry Warsaw95be23d2000-08-25 19:13:37 +0000483
Barry Warsaw33d8d702000-08-30 03:29:58 +0000484# The resulting catalog object currently don't support access through a
485# dictionary API, which was supported (but apparently unused) in GNOME
486# gettext.
Barry Warsaw95be23d2000-08-25 19:13:37 +0000487
Barry Warsaw33d8d702000-08-30 03:29:58 +0000488Catalog = translation