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. translations evolved ruchi varshney pycon 2014

  2. about me @rvarshney on the web

  3. None
  4. 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
  5. ! # 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
  6. # Run extraction $ pybabel extract --mapping-file babel.cfg --output out.po

    <source_dir> ! ! ! ! ! basics
  7. ! # Translations for MYAPP. # Copyright (c) 2014 ORGANIZATION

    ! #: app/views.py:20 #, python-format msgid "Translate me." msgstr "" ! ! basics
  8. basics _("hello!") msgid "hello!" bonjour! translation service message.mo extract compile

    integrate
  9. what could possibly go wrong?

  10. latency

  11. ! def greeting(name, is_welcome): if is_welcome: return _("Hey there!") else:

    return _("Bye Bye") ! ! ! strings before logic
  12. ! 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
  13. ! class Greetings(object): WELCOME_MESSAGE = _("Hey there!”) BYE_MESSAGE = _("Bye!")

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

    python-format msgid "See you later!" msgstr "" ! lost in translation
  15. lost in translation

  16. hooks https://17727.web.pr.dev.hearsaylabs.com/

  17. ! class Greetings(object): WELCOME_MESSAGE = _("Hey there!”) BYE_MESSAGE = _("Bye!")

    NEW_BYE_MESSAGE = _("See you later!") ! ! ! ! ! lost in translation
  18. babel gotchas #: app/views.py:20 #, python-format #, fuzzy msgid "Translate

    them." msgstr "Traduisez-moi"
  19. 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.”
  20. • —no-fuzzy-matching • other useful ones • —ignore-obsolete True •

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

    • send po file for translation • wait… • get translations back • integrate with app • …. mundane dev
  22. automation jenkins/travis translation upload translation download

  23. dev intervention

  24. content management

  25. content management developer friendly apis translator friendly continuous, cross platform

  26. • 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
  27. • 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
  28. questions? @rvarshney we’re hiring!