blob: 1760c7816d51c6da88e56613cbb4a111cc5ee2ba [file] [log] [blame]
Barry Warsaw9e035922000-08-25 19:14:25 +00001import os
2import gettext
3
4def get_qualified_path(name):
5 """Return a more qualified path to name"""
6 import sys
7 import os
8 path = sys.path
9 try:
10 path = [os.path.dirname(__file__)] + path
11 except NameError:
12 pass
13 for dir in path:
14 fullname = os.path.join(dir, name)
15 if os.path.exists(fullname):
16 return fullname
17 return name
18
19# Test basic interface
20os.environ['LANGUAGE'] = 'xx'
21
22mofile = get_qualified_path('xx')
23localedir = os.path.dirname(mofile)
24
25print 'installing gettext'
26gettext.install()
27
28print _('calling bindtextdomain with localedir %s') % localedir
29print gettext.bindtextdomain('gettext', localedir)
30print gettext.bindtextdomain()
31
32print gettext.textdomain('gettext')
33print gettext.textdomain()
34
35# test some translations
36print _(u'mullusk')
37print _(r'Raymond Luxury Yach-t')
38print _(ur'nudge nudge')
39
40# double quotes
41print _(u"mullusk")
42print _(r"Raymond Luxury Yach-t")
43print _(ur"nudge nudge")
44
45# triple single quotes
46print _(u'''mullusk''')
47print _(r'''Raymond Luxury Yach-t''')
48print _(ur'''nudge nudge''')
49
50# triple double quotes
51print _(u"""mullusk""")
52print _(r"""Raymond Luxury Yach-t""")
53print _(ur"""nudge nudge""")
54
55# multiline strings
56print _('''This module provides internationalization and localization
57support for your Python programs by providing an interface to the GNU
58gettext message catalog library.''')
59
60print gettext.dgettext('gettext', 'nudge nudge')
61
62# dcgettext
63##import locale
64##if gettext.dcgettext('gettext', 'nudge nudge',
65## locale.LC_MESSAGES) <> 'wink wink':
66## print _('dcgettext failed')
67
68# test the alternative interface
69fp = open(os.path.join(mofile, 'LC_MESSAGES', 'gettext.mo'), 'rb')
70t = gettext.GNUTranslations(fp)
71fp.close()
72
73gettext.set(t)
74print t == gettext.get()
75
76print _('nudge nudge')