Permalink
Browse files

allow form element translations

  • Loading branch information...
1 parent 1d0b33c commit d05dac220e81391bad2e81356f3de7a68b21e715 @mcdonc mcdonc committed Mar 19, 2013
Showing with 6 additions and 1 deletion.
  1. +6 −1 substanced/widget/__init__.py
@@ -4,7 +4,9 @@
from deform.template import ZPTTemplateLoader
from translationstring import ChameleonTranslate
+from pyramid.i18n import get_localizer
from pyramid.renderers import get_renderer
+from pyramid.threadlocal import get_current_request
class WidgetRendererFactory(object):
"""
@@ -69,12 +71,15 @@ def load(self, template_name):
else:
return self.loader.load(template_name + '.pt')
+def translator(term): # pragma: no cover
+ return get_localizer(get_current_request()).translate(term)
+
def includeme(config): # pragma: no cover
# specify both deform and deform_bootstrap templates as "fallback"
# locations; assume user-supplied templates will be specified using asset
# specs instead.
deform_dir = resource_filename('deform', 'templates/')
deform_bootstrap_dir = resource_filename('deform_bootstrap', 'templates/')
search_path = (deform_bootstrap_dir, deform_dir)
- renderer = WidgetRendererFactory(search_path)
+ renderer = WidgetRendererFactory(search_path, translator=translator)
deform.Form.set_default_renderer(renderer)

0 comments on commit d05dac2

Please sign in to comment.