Tornado – Internationalization


 

Web development often calls for internationalization (i18n), Tornado provides this facility with tornado.locale class.

In the example below, we create request handlers to cater to users request for different locale. For instance, DEHandler renders a standard web page (locale_template.html) in German language after translating the English words from the template.

Translation is governed by de_DE.csv file located under translation folder.

 

Advertisements

One thought on “Tornado – Internationalization

  1. While this article is pretty old, maybe my remark will be useful for someone.
    In current tornado version (4.0.2) method `set_default_locale` just set the default locale globally, not the locale of request. It will be used only if locale can’t be discovered from HTTP headers.
    To set the locale for request, method `get_user_locale` (http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.get_user_locale) must be used:

    class FRHandler(tornado.web.RequestHandler):
    def get_user_locale(self):
    return tornado.locale.get(“fr_FR”)

    def get(self):
    self.render(“locale_template.html”)

    Also check out this article, it describes i18n process in tornado with many details: http://www.lexev.org/en/2015/tornado-internationalization-and-localization/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s