Reputation: 1685
I'm trying to add i18n capability to a little test project i'm working on. I'm using webapp2_extras i18n library. I have the locale folder with compiled translation .mo files created using the babel command-line. The app itself is just one simple django template and a main.py with one handler. When i'm using the gettext method right in the main I do get the translated text but strings inside the template that are wrapped with {% trans %} tag does not get translated. Here's the handler:
class MainHandler(webapp2.RequestHandler):
def get(self):
locale = self.request.GET.get('locale', 'en_US')
i18n.get_i18n().set_locale(locale)
message = i18n.gettext('Hello, world!')
self.response.out.write(template.render("templates/index.html"))
in "message" the string is translated but inside the template the same string wrappwed with {% trans %} isn't.
Thanks,
Upvotes: 2
Views: 483
Reputation: 26647
It is possible to use a custom request handler that enables django's i18n trans tag with google app engine. But much better is use jinja2 like is said here, then the solution is official. You should import jinja2 from webapp2_extras and then your i18n will work and the translation tag for jinja2 will look like {% trans %}
and { % endtrans %}
.
If you must use django here is a link to an old blod post that presents a custom request handler that you can use if you must use django templates: http://blog.yjl.im/2009/02/using-django-i18n-in-google-app-engine.html
But we recommend that you use jinja2. Have you tried it?
Upvotes: 1