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.


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` ( must be used:

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

    def get(self):

    Also check out this article, it describes i18n process in tornado with many details:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.