Thanks, @tipsywacky, I was a little lost with jinja2, babel and GAE, and your code put me on the right path.
I want to share my code for other "stackers", in which you can appreciate a strange thing: don't know why, but I don't need to setup a config var to make all working.
import webapp2
import jinja2
import os
import logging
# Internacionalization functions
from webapp2_extras import i18n
from webapp2_extras.i18n import gettext as _
# Put here the path to the jinja templates, relative to the actual file
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "views"))),
extensions=['jinja2.ext.i18n'],
autoescape=False)
jinja_env.install_gettext_translations(i18n)
# This controller handles the generation of the front page.
class MainPage(webapp2.RequestHandler):
def get(self):
locale = self.request.get('locale', 'es_ES')
i18n.get_i18n().set_locale(locale)
logging.info(_('Hello-World'))
template = jinja_environment.get_template('main.html')
self.response.out.write(template.render())
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
With only this code and your HTML file (and the message.mo files compiled):
<div id="main">
{{ _("Hello-World") }}
</div>
my app makes the translation of the logging text and of the HTML text.
That's wonderful, I spent the full day searching for a way to do localization and finally I got it.
The only thing I don't understand is your config var. Why I don't need it?