Skip to content

Internationalization

ryosuketc edited this page Feb 8, 2021 · 3 revisions
« back to DeveloperGuide

Language codes and locale codes

Person Finder follows the Django convention for "language code" versus "locale code". A language code is a lowercase ISO 639-1 language code, optionally followed by a hyphen and an uppercase ISO 3166-1 two-letter country code. A locale code is like a language code except that it uses an underscore instead of a hyphen. The use of locale and lang for variable and function names in Person Finder should follow this convention.


Selecting the display language

Setting the lang query parameter to a language code sets the display language (on any page). The language code is also saved in a browser cookie, which determines the language when there is no lang parameter.


Translated messages

Localized messages are stored in app/locale in a directory named after the locale code, in .po format. For example, French messages are in app/locale/fr/LC_MESSAGES/django.po. These .po files are compiled into .mo files, which are used at runtime.

Whenever you change strings in the code, you should run tools/update_messages, which will scan the Python code and all the Django templates for strings, update the .po files with new strings, compile them into the appropriate .mo files, and then print a report listing the messages that have missing translations in each language. In general, you will rarely need to run tools/update_messages directly, because running the tests with tools/server_tests automatically runs tools/update_messages.


Adding a new language

Take the following steps to add a new language:

  • Important: stop any local running appservers
  • Run tools/update_messages
  • Create a new directory for the language at app/locale/locale_code/LC_MESSAGES
  • Copy app/locale/en/LC_MESSAGES/django.po into your new directory
  • Edit this new django.po file to add the translated messages for the new language
  • Run tools/update_messages again to compile and convert the new translated messages
  • Add the new language to LANGUAGE_ENDONYMS and LANGUAGE_EXONYMS in app/utils.py
  • Add the new language to the lang-test subdomain in tools/setup.py
  • Run the tests as explained in HowToDevelop
  • Run dev_appserver.py app and then go to http://localhost:8080/?subdomain=lang-test to try out the new language
  • If everything looks good, run hg add to add your new message files, commit, and request a code review
« back to DeveloperGuide
Clone this wiki locally