FormCode i18n - TurboGears

Gregor Horvath <gh-LfrpOBifzZo+ytmZ3SK/[email protected]>
Newsgroups 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


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.