Skip to content

Instantly share code, notes, and snippets.

@ewjoachim
Last active October 31, 2017 08:24
Show Gist options
  • Save ewjoachim/dcb6774d3d4d1c0de7cef3518f406ddb to your computer and use it in GitHub Desktop.
Save ewjoachim/dcb6774d3d4d1c0de7cef3518f406ddb to your computer and use it in GitHub Desktop.
Django, gettext, contexts and comments
from django.utils.translation import ugettext as _
from django.utils.translation import pgettext
# _() means normal translation
_("Hello world")
# Translators: This is a comment
_("Hello world")
# Translators: This is a another comment
_("Hello world")
# pgettext() means translation with context
pgettext("This is a context", "Hello World")
pgettext("This is another context", "Hello World")
# (...)
#. Translators: This is a comment
#. Translators: This is a another comment
#: i18nstrings/i18n.py:4 i18nstrings/i18n.py:7 i18nstrings/i18n.py:10
msgid "Hello world"
msgstr ""
#: i18nstrings/i18n.py:12
msgctxt "This is a context"
msgid "Hello World"
msgstr ""
#: i18nstrings/i18n.py:14
msgctxt "This is another context"
msgid "Hello World"
msgstr ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment