I use babel. It's a library from the trac guys:
It is a gettext wrapper and i18n tools. You can extract messages from
.py and .html files, and then you translate/compile the .po/.mo
catalogs. For a full implementation you can see how it is done in Kay:
http://bitbucket.org/tmatsuo/kay/src/tip/kay/i18n/
-- rodrigo
> - I suppose that the .po / .mo files that open source projects
> traditionally use can not be used in the App Engine world?
Yes, you can use those files with gettext functions. You'll probably
need to wrap those functions and write some utilities to make it
easier to use - but you don't need to do that because there are
excellent libraries that have done it - Babel is the most known in the
python world (I actually don't know any other).
> - Would you have various template files for each languages (like a
> contact.en.html, contact.fr.html, contact.nl.html, etc.) and use the
> appropriate file depending on the language that has been detected from
> the browser header?
No! You would use one template, and have the strings wrapped by a
translation function. The convention is to use a function name "_".
Like:
{{ _("This is my string - I'll translate it later, and if not it'll be
in English forever.") }}
There are issues you'll find, like how to handle singular/plural and
string replacements, but existing solutions cover that.
> - Would you use a single template file, but pass it the strings one by
> one that you would retrieve from the datastore (ouch, just writing
> this solution hurts!)
Absolutelly no. The strings are stored in a .po file, which you
compile into a .mo file. This if you go for the widely used gettext.
> Note: if you execute the following command from inside the GAE dev
> server folder:
> find | xargs -i grep -iH i18n \{\}
> you will see that a lot of files contain the string i18n, and that all
> are related to django. Does that mean that we could use standard
> Django internationalization techniques, or is it just that Google <
> forgot > to remove those files?
I tried to use Django's i18n. Unfortunately Django is too tied to
itself and that library is not reusable outside of Django. Fortunately
later I found a standalone, reusable, well written one: Babel. It
works very well.
-- rodrigo
Without any other external library, you have 2 options:
1. use gettext - http://docs.python.org/library/gettext.html
2. hack and patch django's i18n
The problem with the 2nd option is that your app stays tied to
django's ecosystem - later you need i18n in a small project and you'll
have to add django just for it. Ok, it is a valid solution, I just
personally prefer to use a external library that is not coupled with a
bunch of unrelated things, and avoid all the monkeypatching mess.
-- rodrigo
--
gae-django-cms (GD-cms)
a multi-user CMS running on GAE 一个基于GAE多用户的CMS
sample http://cmsdome.appspot.com/
projects http://code.google.com/p/gae-django-cms/