This is a start to finish guide showing how to do internationalization (i18n) for a Python application. When I added i18n to handroll, I struggled to find clear advice for supporting other languages. This is one opinionated view explaining how I got there.

Table of Contents:

  • Marking strings
  • Extracting the master list
  • Getting translations for other languages
  • Packaging it together
  • Testing out the package
  • Questions?

Overview

To internationalize code, you have to treat user text strings in a certain way. All text strings must be wrapped with a special function call. This special function marks the strings as something that needs translation. Once all the strings are marked, i18n tools can scan your code to make a master list of everything. With the master list available, translators can produce a list of translated strings for each desired language. The translated strings are added back to the Python code and it’s all bundled up into a nice translated final product. Then you may want to test that out.

That’s a lot of stuff, but I’ll explain each part of that process in detail. For the purposes of this guide, all of my example code will refer to the handroll package. If this is your Python code, replace handroll with the name of your top level Python package.

#python #i18n

A Complete Guide to i18n in Python
11.70 GEEK