I know I can run the following code in python shell:
import formencode
ne = formencode.validators.NotEmpty()
formencode.api.set_stdtranslation(languages=["it"])
try:
ne.to_python("")
except formencode.api.Invalid, e:
print str(e)
and get printed
Inserire un valore
Now how do I get the same result im my pyramid app using pyramid_simpleform with Formencode?
I've just found a way to do it, but I'm not sure it's the best one... Anyway, I mixed information from the Mako i18n recipe, the simpleform documentation and how Pylons did it (the PylonsFormEncodeState inside pylons.decorators) and I came up with the following...
I subscribe to a NewRequest event like this:
and then define
add_localizer
: