Hello!
I'm using i18n exactly as described
in
http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/templates/mako_i18n.html,
which works fine for views and templates (mako). But I can't get i18n to
work in my forms (wtforms).
forms.py:
---
from wtforms import Form, ...
from myproject.subscribers import tsf as _ # ???
#from pyramid.i18n import TranslationString as _
class SignupForm(Form):
firstname = TextField(_(u'First name'),
[validators.Required(message=_(u'This field is required.'))])
lastname = TextField(_(u'Last name'),
[validators.Required(message=_(u'This field is required.'))])
email = EmailField(_(u'Email address'),
[validators.Required(message=_(u'This field is required.')),
validators.Email(message=_(u'Invalid email address.'))])
The strings do appear in my locale/.po files, but they are not being used
when rendering the form.
I understand it has something to do with 'request', but don't know how to
set _ = request.translate (as I do it in my views).
I've also
followed
http://wtforms.simplecodes.com/docs/1.0.4/i18n.html#translating-built-in-messages
and made my custom translations object.
forms.py:
---
...
from pyramid.threadlocal import get_current_request
class Translator(object):
def __init__(self, request):
self.translate = request.translate
self.localizer = request.localizer
def gettext(self, string):
return self.translate(string)
def ngettext(self, singular, plural, n):
return self.localizer.pluralize(singular, plural, n)
class ExtendedForm(Form):
def _get_translations(self):
request = get_current_request()
return Translator(request)
class SignupForm(ExtendedForm):
firstname = TextField(_(u'First name'), [validators.Required()])
But this only translates build-in strings ("This field is required.") and
not the labels ("First name").
How/What do I have to import to make i18n work with my forms?
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.