generate html with translation

52 views Asked by At

For a generic form checker I want to generate html <input> fields plus internationalized error messages (and default values, ...) while using templates to define which fields are in the form.

Template example:

...
<form>
  ${structure: make_field('email')}
</form>

Rendered template:

...
<form>
  <input type="text" name="email" ... /><span>error message</span>
</form>

Problem:

The error message for each field is specified using gettext like _('error123'). Because the html string is constructed by code I have to translate() the error message myself. Therefore I have to hand in a localizer to the form checker code which I want to avoid.

Is it possible to move the rendering completely to the template engine. Maybe with macros generated in code?!

0

There are 0 answers