As emocionantes aventuras de um sysadmin linux na procura pelo uptime perfeito!

Turbogears Validators, Widgets and i18n (or how I got it to work)

Posted: novembro 6th, 2006 | Author: coredump | Filed under: Linux e Open Source, Programação | Tags: ,

<Originally posted on the turbogears mail list>

So, for the last days or so I was strugling to get validators, widgets and my proto-app internationalized and ready to translate all the stuff.
Turbogears i18n stuff is already advanced, but when using widgets and validation the application can end a little weird… Mainly with non-translated error messages :) Kinda like engrish, portuglish and other mutations.

I used those as reference, and the latest avaiable TurboGears from the site:

1) Get the .diff file from the turbogears trac. Apply the patch using the normal way. On Windows I used the ported GNU patch (remember to convert the file to the native DOS format, the unix end of line stuff makes patch very angry).
Go to the TurboGears folder (same level as the turbogears one, noticed the capitalization?) and:

# patch -p0 < tg_i18n_fe.diff

It should apply without errors.

2) Get the formencode with gettext support:

svn co temp

but do not do the python install routine. Just get into the directory and copy the full formencode dir to your site-packages/FormEncode you have (again, pay attention to the capitalization on the dir names).
The setuptool appears to be woopsie and I lost some hours because of that. Gettext support will hopefully be integrated on the next release.

3) Put your custom validators on a separated file. I really did not had the time to investigate why, but the discussion on the trac ticket says it’s the best to do, so I did :)

4) Wrap your strings with the little shrimps _(). I did that even with my error messages on the custom validators.

5) Use the normal TG tools to add i18n, collect strings, etc… In the end, on your new locales/%(lang)s/LC_MESSAGES/ dir you should have, and messages.pot (and .mo after you compile). If one of those files are missing, pay attention to the i18n add command output, it’ll give you the location where the file should have been, maybe you have to contribute with a translation for your language, but no sweat, most of the work has been done on the file. And remember, contributing is GOOD. Shrimps too.

6) Well. It should be working by now. I’m pretty sure that it was all I did. I know, it envolves patching TG and using a development FormEncode, but the results are pretty.

Thanks to Gregor Horvath that made the patch, pointed me to the trac post, helped with the formencode problems and has been an all around Nice Guy®.

Technorati Tags: turbogears, formencode

  • Digg
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
  • Twitter

Posts relacionados:

  1. Turbogears, Mysql and UTF. Advice Needed! So, I have this little problem… For design reasons, I...
  2. Kindness of Strangers Tá bom… Vocês ficaram com dó e não me falaram...
  3. Trac Hacks Indispensáveis Então, eu uso bastante o trac como gerenciador de projetos....
  4. Turbogears (ou zope, ou ruby) Behind Apache: Diminuindo o load. E então, muita gente usa frameworks como o Turbogears ou...
  5. A cerveja, os copos e o TurboGears Pois então. Não é que em alguma parte do meu...

No Comments »

Leave a Reply