summaryrefslogtreecommitdiff
path: root/src/zope/i18n/tests/test_zcml.py
diff options
context:
space:
mode:
authorHanno Schlichting <hanno@hannosch.eu>2008-07-06 16:41:50 +0000
committerHanno Schlichting <hanno@hannosch.eu>2008-07-06 16:41:50 +0000
commitd1df2370126fbb184aa960c8d1a7570d36fccd12 (patch)
treef9b1070e39c1e08a260f00e3dd89e64d7495e8d5 /src/zope/i18n/tests/test_zcml.py
parente90ee9d681ee056f4cff7f7ac8e55e5e148785dc (diff)
downloadzope-i18n-d1df2370126fbb184aa960c8d1a7570d36fccd12.tar.gz
Feature: Added support for restricting the available languages. We support an environment variable called `zope_i18n_allowed_languages` now, which is a list of comma or space separated language codes. If the environment variable is set, the ZCML registration will only process those folders which are in the allowed languages list.
Diffstat (limited to 'src/zope/i18n/tests/test_zcml.py')
-rw-r--r--src/zope/i18n/tests/test_zcml.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/zope/i18n/tests/test_zcml.py b/src/zope/i18n/tests/test_zcml.py
index 076929b..4a420cf 100644
--- a/src/zope/i18n/tests/test_zcml.py
+++ b/src/zope/i18n/tests/test_zcml.py
@@ -41,6 +41,12 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase):
def setUp(self):
super(DirectivesTest, self).setUp()
self.context = xmlconfig.file('meta.zcml', zope.i18n)
+ self.allowed = zcml.ALLOWED_LANGUAGES
+ zcml.ALLOWED_LANGUAGES = None
+
+ def tearDown(self):
+ super(DirectivesTest, self).tearDown()
+ zcml.ALLOWED_LANGUAGES = self.allowed
def testRegisterTranslations(self):
self.assert_(queryUtility(ITranslationDomain) is None)
@@ -53,8 +59,23 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase):
path = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
'locale', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
util = getUtility(ITranslationDomain, 'zope-i18n')
+ self.assertEquals(util._catalogs.get('test'), ['test'])
+ self.assertEquals(util._catalogs.get('en'), [unicode(path)])
+
+ def testAllowedTranslations(self):
+ self.assert_(queryUtility(ITranslationDomain) is None)
+ zcml.ALLOWED_LANGUAGES = ('de', 'fr')
+ xmlconfig.string(
+ template % '''
+ <configure package="zope.i18n.tests">
+ <i18n:registerTranslations directory="locale" />
+ </configure>
+ ''', self.context)
+ path = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
+ 'locale', 'de', 'LC_MESSAGES', 'zope-i18n.mo')
+ util = getUtility(ITranslationDomain, 'zope-i18n')
self.assertEquals(util._catalogs,
- {'test': ['test'], 'en': [unicode(path)]})
+ {'test': ['test'], 'de': [unicode(path)]})
def testRegisterDistributedTranslations(self):
self.assert_(queryUtility(ITranslationDomain) is None)
@@ -75,9 +96,9 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase):
path2 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
'locale2', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
util = getUtility(ITranslationDomain, 'zope-i18n')
- self.assertEquals(util._catalogs,
- {'test': ['test', 'test'],
- 'en': [unicode(path1), unicode(path2)]})
+ self.assertEquals(util._catalogs.get('test'), ['test', 'test'])
+ self.assertEquals(util._catalogs.get('en'),
+ [unicode(path1), unicode(path2)])
msg = util.translate(u'Additional message', target_language='en')
self.assertEquals(msg, u'Additional message translated')