[Zope3-checkins] SVN: Zope3/trunk/src/zope/formlib/ We have
internationalized the titles of error messages.
Yuta Kashino
kashino at zope.co.jp
Tue Dec 27 05:41:51 EST 2005
Log message for revision 41043:
We have internationalized the titles of error messages.
Changed:
U Zope3/trunk/src/zope/formlib/form.py
U Zope3/trunk/src/zope/formlib/tests.py
-=-
Modified: Zope3/trunk/src/zope/formlib/form.py
===================================================================
--- Zope3/trunk/src/zope/formlib/form.py 2005-12-27 09:31:38 UTC (rev 41042)
+++ Zope3/trunk/src/zope/formlib/form.py 2005-12-27 10:41:50 UTC (rev 41043)
@@ -748,6 +748,8 @@
zope.app.form.browser.interfaces.IWidgetInputErrorView)
title = getattr(error, 'widget_title', None) # duck typing
if title:
+ if isinstance(title, zope.i18nmessageid.Message):
+ title = zope.i18n.translate(title, context=self.request)
yield '%s: %s' % (title, view.snippet())
else:
yield view.snippet()
Modified: Zope3/trunk/src/zope/formlib/tests.py
===================================================================
--- Zope3/trunk/src/zope/formlib/tests.py 2005-12-27 09:31:38 UTC (rev 41042)
+++ Zope3/trunk/src/zope/formlib/tests.py 2005-12-27 10:41:50 UTC (rev 41043)
@@ -226,6 +226,35 @@
"""
+
+def test_error_views_i18n():
+ """\
+
+ >>> from zope.i18n.simpletranslationdomain import SimpleTranslationDomain
+ >>> from zope.i18n.interfaces import ITranslationDomain
+ >>> messageDic = {('ja', u'Summary'): u'MatomeYaken'}
+ >>> sd = SimpleTranslationDomain('KansaiBen.domain', messageDic)
+ >>> component.provideUtility(provides=ITranslationDomain,
+ ... component=sd,
+ ... name='KansaiBen.domain')
+ >>> from zope.i18n.negotiator import negotiator
+ >>> component.provideUtility(negotiator)
+ >>> _ = zope.i18nmessageid.MessageFactory('KansaiBen.domain')
+ >>> myError = zope.app.form.interfaces.WidgetInputError(
+ ... field_name='summary',
+ ... widget_title=_(u'Summary'))
+ >>> from zope.publisher.browser import TestRequest
+ >>> req = TestRequest()
+ >>> req._environ['HTTP_ACCEPT_LANGUAGE'] = 'ja; q=1.0'
+ >>> mybase = form.FormBase(None, req)
+ >>> mybase.errors = (myError,)
+ >>> save = mybase.error_views()
+ >>> save.next()
+ u'MatomeYaken: <span class="error"></span>'
+
+"""
+
+
def test_form_template_i18n():
"""\
Let's try to check that the formlib templates handle i18n correctly.
More information about the Zope3-Checkins
mailing list