Adding localization feature to a web-project

Thomas Guettler guettli at thomas-guettler.de
Wed Nov 5 16:45:36 CET 2003


Am Wed, 05 Nov 2003 16:16:48 +0100 schrieb Thomas Weholt:

> Hi,
> 
> I'm doing a web-project using Python and was wondering how I can add a
> localization option to my web-pages? Does anybody have any hints or ideas?
> I'm using simpleTal/es as a template-engine.
> 
> I need to let the user specify (or download a language pack ) and customize
> central text elements in a web-portal according to his/her needs.
> 
> If anybody can share some thoughts or examples on how they did this or ideas
> on a system which makes such localization packs easy to maintain, that would
> help alot.

I do it like gettext (with a _() method), without using gettext:

_("the sun shines") --> "Die Sonne scheint"

Pseudo-Code:

def _(string):
    user=get_user() # Problem
    if user.lang=="de":
        return de.translations[string]

File de.py:
translations{
   "the sun shines": "Die Sonne scheint",
   ...
}

If you look at the "Problem" above: You need
to get to the user-data without a root-object.
This is a problem if you use zope. At least
I found no good solution.

I switched to quixote and there I have a customized
publisher, which puts some parts into the global namespace
(in a thread-save way).

Hope that's helps,
 thomas








More information about the Python-list mailing list