Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dbaty/deform
Browse files Browse the repository at this point in the history
  • Loading branch information
dnouri committed Mar 30, 2012
2 parents 30a6e6a + 5f01c94 commit 90cb08c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
30 changes: 30 additions & 0 deletions deform/tests/test_widget.py
Expand Up @@ -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')
Expand Down
10 changes: 8 additions & 2 deletions deform/widget.py
Expand Up @@ -5,6 +5,8 @@
from colander import Invalid
from colander import null

from translationstring import TranslationString

from deform.i18n import _

from deform.compat import (
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 90cb08c

Please sign in to comment.