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

Localization Revisted (aka. Translations Evolved) by Ruchi Varshney

Localization Revisted (aka. Translations Evolved) by Ruchi Varshney

PyCon 2014

April 13, 2014
Tweet

More Decks by PyCon 2014

Other Decks in Technology

Transcript

  1. most common tools are gettext and babel ! import gettext

    as _ print _("Translate me.") ! from babel import dates, numbers dates.format_datetime(date, locale='de') numbers.format_decimal(1.234, locale='de') ! ! basics
  2. ! # Extraction config file (babel.cfg) [python: **.py] [jinja2: **.html]

    [javascript: **.js] ! [extractors] python = babel.messages.extract:extract_python jinja2 = jinja2.ext:babel_extract javascript = babel.messages.extract:extract_javascript ! ! basics
  3. ! # Translations for MYAPP. # Copyright (c) 2014 ORGANIZATION

    ! #: app/views.py:20 #, python-format msgid "Translate me." msgstr "" ! ! basics
  4. ! class Greetings(object): WELCOME_MESSAGE = _("Hey there!") BYE_MESSAGE = _("Bye!")

    ! ! def greeting(name, is_welcome): if is_welcome: return Greetings.WELCOME_MESSAGE else: return Greetings.BYE_MESSAGE strings before logic
  5. ! class Greetings(object): WELCOME_MESSAGE = _("Hey there!”) BYE_MESSAGE = _("Bye!")

    BYE_MESSAGE = _("See you later!") ! ! ! ! ! lost in translation
  6. ! #, python-format msgid "Bye!" msgstr "Au revoir!" ! #,

    python-format msgid "See you later!" msgstr "" ! lost in translation
  7. ! class Greetings(object): WELCOME_MESSAGE = _("Hey there!”) BYE_MESSAGE = _("Bye!")

    NEW_BYE_MESSAGE = _("See you later!") ! ! ! ! ! lost in translation
  8. babel gotchas “strings might be marked as fuzzy — if

    you have fuzzy entries, make sure to check them by hand and remove the fuzzy flag before compiling.”
  9. • —no-fuzzy-matching • other useful ones • —ignore-obsolete True •

    —add-comments TRANSLATOR: • —keyword "_lazy" babel flags
  10. • find the last translation date • run string extraction

    • send po file for translation • wait… • get translations back • integrate with app • …. mundane dev
  11. • sample code • https://github.com/rvarshney/translations • how to i18n and

    l10n (pycon 2013) • http://bit.ly/pyconi18n • https://www.youtube.com/watch?v=QUFPPJMjn6k resources
  12. • python packages and tools • gettext, babel, potpie, polib

    • githooks, webhooks, jenkins, travis • content management • smartling, transifex have known python support • django-rosetta (open source) resources