Skip to content

Instantly share code, notes, and snippets.

@joshbrooks
Last active September 29, 2020 02:58
Show Gist options
  • Save joshbrooks/6ead7b12eb38540e84171ff9324a1e30 to your computer and use it in GitHub Desktop.
Save joshbrooks/6ead7b12eb38540e84171ff9324a1e30 to your computer and use it in GitHub Desktop.
Translation-examples

Positional Text

You can include a placeholder to add for example user name, and in translations where word order changes

output = _('Today is %(month)s %(day)s.') % {'month': m, 'day': d}
{% blocktrans %}Are you sure you want to delete this {{activity_singular_lower}}?{% endblocktrans %}
#, python-format
msgid "Are you sure you want to delete this %(activity_singular_lower)s?"
msgstr ""
#, python-format
msgid "Are you sure you want to delete this %(activity_singular_lower)s?"
msgstr "ဤ%(activity_singular_lower)sကို ဖျက်လိုတာသေချာပါသလား?"

Plural Forms

As a developer: ngettext and two strings for translation

ngettext(
    'there is %(count)d project',
    'there are %(count)d projects',
    count
)

As a Translator

#, python-format
msgid "there is %(count)d project"
msgid_plural "there are %(count)d projects"
msgstr[0] ""
msgstr[1] ""

Basic Plurals

As a translator my job might get more difficult depending on the language. Most languages which we're familiar with have 2 forms: One and More-than-one expressed as

Plural-Forms: nplurals=2; plural=n != 1;

More Complex Languages

Russian has 3 plural forms

Via gettext manual:

Plural-Forms: nplurals=3; \
    plural=n%10==1 && n%100!=11 ? 0 : \
           n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;

Not as bad as you might think

It's extra work for our translators but not as a bad as you might think

Russian would include a third case here msgstr[2] to cover the third case Arabic would include [0] to [5] as there are six plural forms

Simple Example

from django.utils.translation import gettext_lazy as _
project_reference = _("Project Reference")

The developer runs makemessages

# .....
msgid "Project Reference"
msgstr ""

The translator works on the "po" file

# .....
msgid "Project Reference"
msgstr "စီမံကိန်း မန်နေဂျာ"

The developer makes sure that the changes get into our codebase and redeploys

This makes the "mo" file which is not human readable

(unreadable)

Rosetta link on staging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment