diff options
author | Barry Warsaw <barry@python.org> | 2000-08-25 19:14:25 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2000-08-25 19:14:25 (GMT) |
commit | 9e035921494cb8f101c3bfc22956fa968c6ab41f (patch) | |
tree | 001d142197d2bcc9d2b511432fda00ae50aaf702 /Lib/test | |
parent | 95be23dc8626684caa268df7ff7749fcb89adddf (diff) | |
download | cpython-9e035921494cb8f101c3bfc22956fa968c6ab41f.zip cpython-9e035921494cb8f101c3bfc22956fa968c6ab41f.tar.gz cpython-9e035921494cb8f101c3bfc22956fa968c6ab41f.tar.bz2 |
Test suite for new gettext.py module.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_gettext.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py new file mode 100644 index 0000000..1760c78 --- /dev/null +++ b/Lib/test/test_gettext.py @@ -0,0 +1,76 @@ +import os +import gettext + +def get_qualified_path(name): + """Return a more qualified path to name""" + import sys + import os + path = sys.path + try: + path = [os.path.dirname(__file__)] + path + except NameError: + pass + for dir in path: + fullname = os.path.join(dir, name) + if os.path.exists(fullname): + return fullname + return name + +# Test basic interface +os.environ['LANGUAGE'] = 'xx' + +mofile = get_qualified_path('xx') +localedir = os.path.dirname(mofile) + +print 'installing gettext' +gettext.install() + +print _('calling bindtextdomain with localedir %s') % localedir +print gettext.bindtextdomain('gettext', localedir) +print gettext.bindtextdomain() + +print gettext.textdomain('gettext') +print gettext.textdomain() + +# test some translations +print _(u'mullusk') +print _(r'Raymond Luxury Yach-t') +print _(ur'nudge nudge') + +# double quotes +print _(u"mullusk") +print _(r"Raymond Luxury Yach-t") +print _(ur"nudge nudge") + +# triple single quotes +print _(u'''mullusk''') +print _(r'''Raymond Luxury Yach-t''') +print _(ur'''nudge nudge''') + +# triple double quotes +print _(u"""mullusk""") +print _(r"""Raymond Luxury Yach-t""") +print _(ur"""nudge nudge""") + +# multiline strings +print _('''This module provides internationalization and localization +support for your Python programs by providing an interface to the GNU +gettext message catalog library.''') + +print gettext.dgettext('gettext', 'nudge nudge') + +# dcgettext +##import locale +##if gettext.dcgettext('gettext', 'nudge nudge', +## locale.LC_MESSAGES) <> 'wink wink': +## print _('dcgettext failed') + +# test the alternative interface +fp = open(os.path.join(mofile, 'LC_MESSAGES', 'gettext.mo'), 'rb') +t = gettext.GNUTranslations(fp) +fp.close() + +gettext.set(t) +print t == gettext.get() + +print _('nudge nudge') |