18 Оттенков I18n

25
18 оттенков I18n

Transcript of 18 Оттенков I18n

Page 1: 18 Оттенков I18n

18 оттенков I18n

Page 2: 18 Оттенков I18n

Localization Internationalization

Page 3: 18 Оттенков I18n

catgets VS gettext

1995

Page 4: 18 Оттенков I18n

 [language[_territory][.codeset][@modifier]]

Locale

en_GB.UTF-8@variant

Page 5: 18 Оттенков I18n

Messages

Dates

Numbers

Currency

en_GB

Locale

Page 6: 18 Оттенков I18n

More about Localization• Images• Sound• Video• Cultural perception• Taxes

Page 7: 18 Оттенков I18n

gettext features

• Messages• Plural forms• Context

Page 8: 18 Оттенков I18n

Django I18n tools

Page 9: 18 Оттенков I18n

• gettext• Formats• Timezones

I18n features

Page 10: 18 Оттенков I18n

workflow

Me InterpreterLocalizedProduct

POMO

Page 11: 18 Оттенков I18n

from django.utils.translation import gettext_noop as _noopfrom django.utils.translation import gettext as _{ _noop(”Winnie rhyme”): _("It's a very funny thought that, if Bears were Bees," "They'd build their nests at the bottom of trees." "And that being so (if the Bees were Bears)," "We shouldn't have to climb up all these stairs.”)}

✪ python manage.py makemessages

Page 12: 18 Оттенков I18n

Portable ObjectsPO files

#: main.py:3msgid """It's a very funny thought that, if Bears were Bees,""They'd build their nests at the bottom of trees.""And that being so (if the Bees were Bears),""We shouldn't have to climb up all these stairs.”msgstr ""

Page 13: 18 Оттенков I18n

Pootle Server

Page 14: 18 Оттенков I18n
Page 15: 18 Оттенков I18n

Custom Solution

http://rannts.ru/meetups/1/l10n/

Legacy?Customer?

Page 16: 18 Оттенков I18n

#: main.py:3msgid """It's a very funny thought that, if Bears were Bees,""They'd build their nests at the bottom of trees.""And that being so (if the Bees were Bears),""We shouldn't have to climb up all these stairs.”msgstr """Если б мишки были пчёлами, то они бы нипочём, никогда ”"и не подумали так высо́ко строить дом… Ой!"

✪ python manage.py compilemessages

Page 17: 18 Оттенков I18n
Page 18: 18 Оттенков I18n

Provide more context@classmethoddef get_table_caption(cls): # Translators: Taxable or Non-Taxable Donations return cls.prefix + _(' Donations')

#: Translators: Taxable or Non-Taxable Donations #: source.py:3 msgid """Donations"msgstr ""

source

PO

Page 19: 18 Оттенков I18n

Avoid dynamic string creating@propertydef prefix(self): if self.gov_state in ['CA', 'TX', 'FL']: # Translators: Taxable Donations return _('Taxable') else: # Translators: Non-Taxable Donations return _('Non-Taxable')

def get_table_caption(self): # Translators: Taxable or Non-Taxable Donations return self.prefix + _('Donations'))

Words sequence cannot be changed

Page 20: 18 Оттенков I18n

What if nothing to do?

Insert right to the PO files

Page 21: 18 Оттенков I18n

python-babel

Flask-Babel

Same features. Both uses gettext.

babel-django

Page 22: 18 Оттенков I18n

Python gettext standard libraryGNU gettext API

import gettext

gettext.gettext('EOD Report')

Page 23: 18 Оттенков I18n

More – pymorphy – pymorphy2

Русский, Белорусский, Украинский.Морфологический анализ.

(род, число, падеж)

pymorphy-django

Page 24: 18 Оттенков I18n

mystem

Yandex

Морфологический анализ

cli интерфейс

Page 25: 18 Оттенков I18n

Informative Links• History of GNU gettext

https://www.gnu.org/software/gettext/manual/html_node/gettext_219.html#History

https://www.w3.org/International/questions/qa-i18n.ru.php