Skip to content
Browse files

Merge branch 'master' of https://github.com/dbaty/deform

  • Loading branch information...
2 parents 30a6e6a + 5f01c94 commit 90cb08cba7231aff2c838538e108338203ae3458 @dnouri dnouri committed Mar 30, 2012
Showing with 38 additions and 2 deletions.
  1. +30 −0 deform/tests/test_widget.py
  2. +8 −2 deform/widget.py
View
30 deform/tests/test_widget.py
@@ -1222,6 +1222,36 @@ def test_serialize_add_subitem_translates_title(self):
self.assertEqual(renderer.kw['add_subitem_text'].interpolate(),
'Yo titel')
+ def test_serialize_add_subitem_translates_title_with_default_domain(self):
+ from colander import null
+ # By default, we get a TranslationString whose domain is 'deform'
+ renderer = DummyRenderer('abc')
+ schema = DummySchema()
+ field = DummyField(schema, renderer, {'title': 'titel'})
+ inner = DummyField()
+ field.children=[inner]
+ widget = self._makeOne()
+ widget.add_subitem_text_template = 'Yo ${subitem_title}'
+ widget.serialize(field, null)
+ self.assertEqual(renderer.kw['add_subitem_text'].domain, 'deform')
+
+ def test_serialize_add_subitem_translates_title_with_another_domain(self):
+ from colander import null
+ from translationstring import TranslationStringFactory
+ renderer = DummyRenderer('abc')
+ schema = DummySchema()
+ field = DummyField(schema, renderer, {'title': 'titel'})
+ inner = DummyField()
+ field.children=[inner]
+ widget = self._makeOne()
+ # Here we provide our own TranslationString with a custom domain
+ custom_domain = 'not_deform'
+ _ = TranslationStringFactory(custom_domain)
+ widget.add_subitem_text_template = _('Yo ${subitem_title}')
+ widget.serialize(field, null)
+ self.assertEqual(renderer.kw['add_subitem_text'].domain,
+ custom_domain)
+
def test_serialize_add_subitem_translates_description(self):
from colander import null
renderer = DummyRenderer('abc')
View
10 deform/widget.py
@@ -5,6 +5,8 @@
from colander import Invalid
from colander import null
+from translationstring import TranslationString
+
from deform.i18n import _
from deform.compat import (
@@ -1033,8 +1035,12 @@ def serialize(self, field, cstruct, readonly=False):
subitem_title=translate(item_field.title),
subitem_description=translate(item_field.description),
subitem_name=item_field.name)
- add_subitem_text = _(self.add_subitem_text_template,
- mapping=add_template_mapping)
+ if isinstance(self.add_subitem_text_template, TranslationString):
+ add_subitem_text = self.add_subitem_text_template % \
+ add_template_mapping
+ else:
+ add_subitem_text = _(self.add_subitem_text_template,
+ mapping=add_template_mapping)
return field.renderer(template,
field=field,
cstruct=cstruct,

0 comments on commit 90cb08c

Please sign in to comment.
Something went wrong with that request. Please try again.