$30 off During Our Annual Pro Sale. View Details »

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

    View Slide

  2. about me
    @rvarshney on the web

    View Slide

  3. View Slide

  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

    View Slide

  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

    View Slide

  6. # Run extraction
    $ pybabel extract --mapping-file
    babel.cfg --output out.po
    !
    !
    !
    !
    !
    basics

    View Slide

  7. !
    # Translations for MYAPP.
    # Copyright (c) 2014 ORGANIZATION
    !
    #: app/views.py:20
    #, python-format
    msgid "Translate me."
    msgstr ""
    !
    !
    basics

    View Slide

  8. basics
    _("hello!")
    msgid "hello!"
    bonjour!
    translation service
    message.mo
    extract compile integrate

    View Slide

  9. what could possibly
    go wrong?

    View Slide

  10. latency

    View Slide

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

    View Slide

  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

    View Slide

  13. !
    class Greetings(object):
    WELCOME_MESSAGE = _("Hey there!”)
    BYE_MESSAGE = _("Bye!")
    BYE_MESSAGE = _("See you later!")
    !
    !
    !
    !
    !
    lost in translation

    View Slide

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

    View Slide

  15. lost in translation

    View Slide

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

    View Slide

  17. !
    class Greetings(object):
    WELCOME_MESSAGE = _("Hey there!”)
    BYE_MESSAGE = _("Bye!")
    NEW_BYE_MESSAGE = _("See you later!")
    !
    !
    !
    !
    !
    lost in translation

    View Slide

  18. babel gotchas
    #: app/views.py:20
    #, python-format
    #, fuzzy
    msgid "Translate them."
    msgstr "Traduisez-moi"

    View Slide

  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.”

    View Slide

  20. • —no-fuzzy-matching
    • other useful ones

    • —ignore-obsolete True

    • —add-comments TRANSLATOR:
    • —keyword "_lazy"
    babel flags

    View Slide

  21. • find the last translation date

    • run string extraction

    • send po file for translation

    • wait…

    • get translations back

    • integrate with app

    • ….
    mundane dev

    View Slide

  22. automation
    jenkins/travis
    translation
    upload
    translation
    download

    View Slide

  23. dev intervention

    View Slide

  24. content management

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  28. questions?
    @rvarshney
    we’re hiring!

    View Slide