Hi,
> I'm having some troubles with FormEncode and internationalization.
> What I'm trying to do is to make FE to display properly translated
> messages for those form fields that are not valid. After a lot of
> trials and errors I found that (using paster shell):
>
>>>> formencode.api.set_stdtranslation(domain='FormEncode', languages=['it'])
>>>> formencode.api._stdtrans('Please enter a value')
>
> works as expected and I get the translated message. However:
>
>>>> pylons.decorators.formencode_gettext('Please enter a value')
>
> gives me the original message (i.e. in english). What I don't
> understand here is that in pylons/decorators/__init__.py there is the
> following import statament:
>
> from formencode.api import _stdtrans as formencode_gettext
>
> so calling pylons.decorators.formencode_gettext() should give the same
> result as calling formencode.api._stdtrans(). But it doesn't!
>
> It's like the former set_stdtranslation() call has no effect when I
> call _stdtrans() from within pylons. But I really don't understand
> what's going on here. Any help?
While it looks the same it is not:
>>> formencode.api._stdtrans
<bound method GNUTranslations.ugettext of <gettext.GNUTranslations
instance at 0x00C63288>>
>>> pylons.decorators.formencode_gettext
<bound method NullTranslations.ugettext of <gettext.NullTranslations
instance at 0x00D405D0>>
In my opinion you shouldn't use this function directly. decorators
module exports only jsonify and validate functions. Use them.
That's how I solved validate problem:
from pylons.i18n import set_lang
class PeklaStateFactory(object):
def __call__(self):
set_lang('it')
formencode.api.set_stdtranslation(domain="FormEncode", languages=['it'])
return None
state_factory = PeklaStateFactory()
That's how you can use state_factory with tosca widgets validate:
@validate(form=banner_form, error_handler='edit', state_factory=state_factory)
Pylons validate should use state (not state_factory) but I have not tested that.
--
Dalius
http://blog.sandbox.lt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---