Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Becoming a MutltiLingual SuperHero in Django v2.0

Becoming a MutltiLingual SuperHero in Django v2.0

In this talk, we’ll see how we make a language agnostic backend, to serve our app in different languages, based on what language the client wants to communicate in.

We’ll see how to support translation for static data and dynamic data, using various third-party services.

We'll also learn to retain language context in Async tasks ;)

Sanyam Khurana

October 15, 2018
Tweet

More Decks by Sanyam Khurana

Other Decks in Programming

Transcript

  1. Becoming a Multilingual Super Hero in Django (v2.0) Sanyam Khurana

    CuriousLearner ErSanyamKhurana SanyamKhurana.com DjangoCon US 2018
  2. def __who_am_i__(): • One of you! A part of the

    community • CPython contributor and bug triage access on bugs.python.org • Contributor to Gecko Engine, add-ons, Marionette, TaskCluster • GSoC 2018 Mentor for Debian • RGSoC 2016 Mentor
  3. Selecting Language in the order of preference • Language prefix

    in requested URL (Eg: /en/api/resource) • LANGUAGE_SESSION_KEY key in current user's session • django_language cookie determined by LANGUAGE_COOKIE_NAME • Accept-Language header • Fallback to LANGUAGE_CODE in settings
  4. • Language prefix in requested URL • LANGUAGE_SESSION_KEY key in

    current user's session • django_language cookie determined by LANGUAGE_COOKIE_NAME • Accept-Language header • LANGUAGE_CODE setting
  5. GOTCHA #2 i18n tag should be loaded in every file,

    even if it extends another file that already has it loaded.
  6. • Language prefix in requested URL • LANGUAGE_SESSION_KEY key in

    current user's session • django_language cookie determined by LANGUAGE_COOKIE_NAME • Accept-Language header • LANGUAGE_CODE setting
  7. • Language prefix in requested URL • LANGUAGE_SESSION_KEY key in

    current user's session • django_language cookie determined by LANGUAGE_COOKIE_NAME • Accept-Language header • LANGUAGE_CODE setting
  8. GOTCHA #8 Check in django shell if the translations are

    working with activate and ugettext