Change the future

Sunday 2:30 p.m.–3 p.m.

Internationalization and Localization Done Right

Ruchi Varshney

Audience level:
Best Practices/Patterns


A short intro to all aspects of making your Python web app ready for an international audience, right from marking Python source, templates and Javascript for translation to working with translation services, maintaining and testing translation files. The talk will cover details on Python gettext and open-source packages such as Babel and Potpie. Examples are based on the Django i18n framework.


Talk Overview


  • Quick personal intro
    • Who am I
    • Hearsay Social and what we do
  • Why internationalize/localize?
  • Internationalization vs. Localization
  • What needs to be accounted for
    • Translation of text
    • Formatting of dates, times, numbers
    • Time zones

Prepping for Translation

  • Language/locale detection
  • Middleware
  • Session language key vs. HTTP Accept-Language
  • Python source
    • gettext, ugettext, pgettext, npgettext
    • gettext vs. gettext_lazy
    • dbgettext
    • Babel libraries for format_datetime, format_number based on locale/timezone
  • Templates
    • trans/blocktrans tags
    • gettext/ngettext
    • Filters for format_datetime, format_number
    • Inline javascript?
  • Javascript
    • gettext/interpolate
    • Localized datetime pickers

Working with Message Files

  • File format (.po files)
  • Generation
    • Babel translation utilities that work across the board for source, templates and javascript
    • Integration with setuptools/distutils
  • Translation services
    • How they work?
    • Translation memory
  • Compilation (.mo files)

Testing and Maintenance

  • Assigning a test locale and using Potpie to generate test translations that push the limits of your UI and unicode support
  • Jenkins CI for translation generation/checking/statistics with Polib
  • Dealing with half translated sites/Google translate for auto translations
  • Integration with translation services (tools like Transifex, Freeway etc.)


  • Same words with different meaning (using msg_context)
  • Comments for translators (using comment tags/pgettext)
  • Babel does not catch import aliases
  • Dealing with HTML tags/newlines in message files

Useful Links/References