Upload
aleksey-kutepov
View
106
Download
0
Embed Size (px)
Citation preview
18 оттенков I18n
Localization Internationalization
catgets VS gettext
1995
[language[_territory][.codeset][@modifier]]
Locale
en_GB.UTF-8@variant
Messages
Dates
Numbers
Currency
en_GB
Locale
More about Localization• Images• Sound• Video• Cultural perception• Taxes
gettext features
• Messages• Plural forms• Context
Django I18n tools
• gettext• Formats• Timezones
I18n features
workflow
Me InterpreterLocalizedProduct
POMO
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
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 ""
Pootle Server
Custom Solution
http://rannts.ru/meetups/1/l10n/
Legacy?Customer?
#: 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
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
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
What if nothing to do?
Insert right to the PO files
python-babel
Flask-Babel
Same features. Both uses gettext.
babel-django
Python gettext standard libraryGNU gettext API
import gettext
gettext.gettext('EOD Report')
More – pymorphy – pymorphy2
Русский, Белорусский, Украинский.Морфологический анализ.
(род, число, падеж)
pymorphy-django
mystem
Yandex
Морфологический анализ
cli интерфейс
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