Ticket #296 (closed enhancement: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] integrate gettext with formencode validation

Reported by: max Owned by: pjenvey
Priority: normal Milestone: 0.9.7
Component: I18N & Unicode Version: 0.9.5
Severity: normal Keywords: i18n formencode validation
Cc:

Description

The patch provides a mean to localize error messages in application-specific validators as well as use existing localization of standard formencode validators. Please see detailed comments inline.

Attachments

formencode_state.patch Download (3.0 KB) - added by max 3 years ago.

Change History

Changed 3 years ago by max

Changed 3 years ago by pjenvey

  • milestone changed from 0.9.6 to 0.9.7

do we want to force, or default to a state object in validate? we can now pass a custom state argument as per #297

Changed 3 years ago by max

I think default is better, since users may want to override localization function in certain circumstances. E.g.:

state['_'] = state.get('_', pylons_formencode_gettext)

Changed 3 years ago by guest

I wished that the @validate decorator would by default pass through the "_" function so that formencode/validator error messages can be localized just like any other string in a Pylons project. Passing PylonsFormEncodeStateObject? through @validate as a state is a bit uncomfortable. I would prefer a global switch that tells formencode/@validate to use Pylons i18n methods.

formencode.api.set_stdtranslation by default just seems to allow one localedir which is on my system set to '/usr/lib/python2.4/site-packages/formencode/i18n'. So I can't add my own localisations anyway with formencode.

Changed 2 years ago by pjenvey

I think I'd prefer defaulting to Max's state object rather than a global switch

It would be nice if we could tie formencode's i18n a little bit better with a Pylons project's. Maybe if it could use our ugettext, then fallback to its own if it failed? That needs to be proposed on the FormEncode? mailing list, anyway

Changed 2 years ago by pjenvey

  • status changed from new to closed
  • resolution set to fixed

Added Max's patch in [4695a3e82e33]. I'm passing just the class, not an instance of it, as the state since _ is a static method anyway

Thanks Max!

Note: See TracTickets for help on using tickets.


Powered by Pylons - Contact Administrators