FormCode i18n - TurboGears
Gregor Horvath <[email protected]>
| Newsgroups | gmane.comp.web.turbogears,gmane.comp.python.formencode |
|---|---|
| Organization | Ing. Gregor Horvath, Industrieberatung & Softwareentwicklung |
| Message-ID | <[email protected]> |
Hi,
I made some investigation on the topic.
1. Message translation time
The straightforward and standard way of i18n would be to pack the
strings in validators.py into the function _("some text").
The problem is that FormEncode executes this function at import time of
validators.py (because of __classinit__).
Therefore it is not possible not change the language or the gettext
function after the import with this approach.
Also at this time TG's i18n module is not installed yet. TG integration
is therefore not possible.
2. Lazystring
A solution would be to use TG's lazystring. But FormEncode does not work
with them out of the box because it expects strings or buffers as
messages. Unfortunatly at the moment I do not have the time and
knowlegde to hack FormEncode to support lazystrings.
3. Translation in message
Another approach is to translate the message on the fly with an outside
gettext function like it is done in the patch from January.
The problem is that this does not work for using FormEncode standalone.
Also I do not see how to extract the messages automatically when there
are no _("") functions. Also one has to fiddle with the state object,
and TG has to supply it along with a gettext function.
4. My solution (KISS)
Since for my current project I only need statically translated messages
and TG integration is not necessary at the moment (for example determine
the language out of the HTTP headers for multilanguage projects)
solution 1 is enough for me.
Therefore I'll create a patch for validators.py and the german translation.
If someone is interested in it please drop me a note.
--
Greg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---