mς γΈEc@s“dZdkZdkZedjo$eeiieiddƒƒndklZl Z d„Z d„Z d„Z edjo e ƒndS( sYUnit tests for the i18n framework $Id: test_i18n.py 71088 2006-11-06 14:46:59Z yuppie $ Nt__main__is framework.py(ssetUpstearDowncCsdS(s_ Test the i18n directive. First, we need to register the ZCML directive: >>> import zope.i18n >>> from Products.Five import zcml >>> zcml.load_config('meta.zcml', zope.i18n) Let's register the gettext locales using the ZCML directive: >>> configure_zcml = ''' ... ... ... ''' >>> zcml.load_string(configure_zcml) Now, take an arbitrary message id from that domain: >>> from zope.i18nmessageid import MessageFactory >>> from zope.i18n import translate >>> _ = MessageFactory('fivetest') >>> msg = _(u'explicit-msg', u'This is an explicit message') As you can see, both the default functionality and translation to German work: >>> translate(msg) u'This is an explicit message' >>> translate(msg, target_language='de') u'Dies ist eine explizite Nachricht' N((((t</data/zmath/zope/lib/python/Products/Five/tests/test_i18n.pyttest_directives!cCsdS(sW Test FiveTranslationService. First we need the GlobalTranslationService: >>> from Products.PageTemplates import GlobalTranslationService >>> GTS = GlobalTranslationService.getGlobalTranslationService() Now, take an arbitrary message id from an arbitrary domain: >>> from zope.i18nmessageid import MessageFactory >>> from zope.i18n import translate >>> _ = MessageFactory('random') >>> msg = _(u'explicit-msg', u'This is an explicit message') By default, the i18n message is translated by the DummyTranslationService: >>> GTS.translate('default', msg, target_language='test') u'This is an explicit message' Now, register the TestMessageFallbackDomain: >>> from zope.component import provideUtility >>> from zope.i18n.testmessagecatalog import TestMessageFallbackDomain >>> provideUtility(TestMessageFallbackDomain) The i18n message is now translated by the TestMessageFallbackDomain: >>> GTS.translate('default', msg, target_language='test') u'[[random][explicit-msg (This is an explicit message)]]' N((((Rttest_FiveTranslationService;scCs dkl}|dtdtƒS(N(s DocTestSuitetsetUpttearDown(tzope.testing.doctestt DocTestSuiteRR(R((Rt test_suite[s (t__doc__tostsyst__name__texecfiletpathtjointzope.component.testingRRRRRt framework(RRRR RRR ((Rt?s $ #