vendor/Five/1.2b-r20590

view tests/test_i18n.py @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2004, 2005 Zope Corporation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 """Unit tests for the i18n framework
16 $Id: test_i18n.py 14595 2005-07-12 21:26:12Z philikon $
17 """
18 import os, sys
19 if __name__ == '__main__':
20 execfile(os.path.join(sys.path[0], 'framework.py'))
22 def test_directive():
23 """
24 Test the i18n directive
26 >>> from zope.app.tests.placelesssetup import setUp, tearDown
27 >>> setUp()
29 First, we need to register the ZCML directive:
31 >>> import zope.app.i18n
32 >>> from Products.Five import zcml
33 >>> zcml.load_config('meta.zcml', zope.app.i18n)
35 Let's register the gettext locales using the ZCML directive:
37 >>> configure_zcml = '''
38 ... <configure xmlns="http://namespaces.zope.org/zope"
39 ... xmlns:i18n="http://namespaces.zope.org/i18n"
40 ... package="Products.Five.tests">
41 ... <i18n:registerTranslations directory="locales" />
42 ... </configure>'''
43 >>> zcml.load_string(configure_zcml)
45 Now, take an arbitrary message id from that domain:
47 >>> from zope.i18nmessageid import MessageIDFactory
48 >>> from zope.i18n import translate
49 >>> _ = MessageIDFactory('fivetest')
50 >>> msg = _(u'explicit-msg', u'This is an explicit message')
52 As you can see, both the default functionality and translation to
53 German work:
55 >>> translate(msg)
56 u'This is an explicit message'
57 >>> translate(msg, target_language='de')
58 u'Dies ist eine explizite Nachricht'
61 Clean up:
63 >>> tearDown()
64 """
66 def test_suite():
67 from Testing.ZopeTestCase import ZopeDocTestSuite
68 return ZopeDocTestSuite()
70 if __name__ == '__main__':
71 framework()