Ticket #1136 (closed enhancement: fixed)
[PATCH] Enable formencode and turbogears validator translation
Reported by: | ghorvath | Owned by: | anonymous |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.2 |
Component: | unassigned | Version: | 1.0.1 |
Severity: | normal | Keywords: | |
Cc: |
Description
This enables the translation of formencode and turbogears validator messages. Currently the branch http://svn.formencode.org/FormEncode/branches/gettext-enabled/ is required to work with this.
tg-admin i18n add
also installs the FormEncode.mo and TurboGears.mo files into the project locale directory.
The patch worked also for the 1.0 branch for me.
Attachments
Change History
comment:1 Changed 12 years ago by alberto
Everything seems fine here (running the 1.0 branch). I've tested with an "es" locale file and messages are being translated as expected.
However, having to change "_" to a dummy function before declaring validators and restoring back to the original "_" after is a real pain in modules that mix validators and other "translatable" objects.
Example:
dummy_ = lambda x: x orig_ = _ _ = dummy_ class MyValidator(FancyValidator): messages = { 'foo': _("A foo ocurred"), # Needs dummy } .... _ = orig_ class MyWidget(FormField): label = _("This is a label") # Needs TG's lazygettext ....
Maybe a hack on FE to avoid the "TypeError?: Error when calling the metaclass bases" error? (or should I just be a good boy and move all validators into a separate module? ;) )
Thanks! Alberto
comment:2 Changed 12 years ago by ghorvath
I think you don't need the dummy function in your module. Just use the standard messages.mo TG mechanism for message extraction to the messages.mo file for your Validators and Widgets. I just wanted to seperate the standard translations from the custom one's.
comment:3 Changed 12 years ago by alberto
Unfortunately I think I do. For tg-admin i18n collect to catch them I need to wrap them in _(), However if I do so without setting _ to a dummy I get the mentioned TypeError?. If I don't restore it, then the strings in the widget will not get translated.
However, this seems like a minor nuisance taking into account that I'm already moving custom validators to separate modules and I'm feeling better by doing so. So don't break your head too much on it. On the other hand, I'm not sure where other users are defining their validators so this might come back biting later...
Alberto
comment:4 Changed 12 years ago by ghorvath
Ah, ok, now I understand. You are correct. At the moment I think the solution is to have the validators in a seperate module.
comment:5 Changed 11 years ago by ghorvath
The gettext enabled branch
http://svn.formencode.org/FormEncode/branches/gettext-enabled/
is now merged into the main trunk
http://svn.formencode.org/FormEncode/trunk
and will be available in the next formencode release.
comment:6 Changed 11 years ago by alberto
I believe this functionality is *essential* to a i18nized app. Once FormEncode's next release includes the i18n changes (*) I think we should apply this to the stable branch too. I mean, I consider not having this functionallity a bug ;) Opinions?
(*) Does anyone have an idea of when is that going to be? Ian?
comment:7 Changed 11 years ago by alberto
I was about to apply this to the trunk for a wider audience testing but we need FormEncode from SVN to use it. Could we have a link to FormEncodes? Trunk in http://www.turbogears.org/preview/download/index.html so easy_install can do it's magic.
The link should be like http://svn.formencode.org/FormEncode/trunk#egg-FormEncode-egg
easy_install should take care of installing a checkout from there.
For the mean time I'll comitt the patch. This would require trunk users to install FormEncode from svn trunk themselves until the link is placed in tg/downloads.
When the link is there please close the patch. Thanks
Alberto
comment:8 Changed 11 years ago by alberto
Oooops, that link should be: http://svn.formencode.org/FormEncode/trunk#egg-FormEncode-dev
Sorry
comment:9 Changed 11 years ago by alberto
Ok, now for real... http://svn.formencode.org/FormEncode/trunk#egg=FormEncode-dev
comment:10 Changed 11 years ago by jorge.vargas
this should be commited after FE is released and needs to make a package bump
comment:11 Changed 11 years ago by alberto
- Milestone changed from 1.1 to __unclassified__
Batch moved into unclassified from 1.1 to properly track progress on the later
comment:12 in reply to: ↑ description Changed 11 years ago by cvogler
Replying to ghorvath:
This ticket is referenced from the TurboGears Internationalization page at http://docs.turbogears.org/1.0/Internationalization, but the patch does no longer work out of the box with the current TurboGears release 1.0.1 and FormEncode 0.7.1. The TurboGears.mo file is missing, the tg-admin i18n add command looks for TurboGears.mo in the wrong path, and the validation message for the MultipleSelection? validator was left untranslated.
I will attach a new patch against TurboGears 1.0.1 in a minute that should fix these problems.
Changed 11 years ago by cvogler
-
attachment
tg_i18n_fe-1.0.1.diff
added
Patch against Turbo Gears 1.0.1 release with FormEncode 0.7.1
comment:13 Changed 11 years ago by alberto
- Version changed from trunk to 1.0.1
- Milestone changed from __unclassified__ to 1.0.2
comment:14 Changed 11 years ago by alberto
- Status changed from new to closed
- Resolution set to fixed
Applied at [2878]. Thanks! :)
Alberto