Understanding msgctxt in .po translation files

Hi all,

this is a followup to my post here: Plone gettext .po - msgctxt support?

When a msgctxt marker is included in a translation file, any following terms are not being picked up by the translation machinery, even though they are present in the compiled .mo file (I used virtaal to check this).

This was quite unexpected. Feature, bug? If a bug, where to file a report or PR?

-Norbert

Edited to fix my use of "context" while using translate()

zope.i18n doesn't seem to support a msgctxt parameter
https://github.com/zopefoundation/zope.i18n/blob/master/src/zope/i18n/init.py

example

./my_package/locales/it/LC_MESSAGES/my_package.po

msgid "ham"
msgstr "prosciutto"

msgctxt "masculine"
msgid "cooked"
msgstr "cotto"

msgid "cheese"
msgstr "formaggio"

msgid "ice"
msgstr "ghiaccio"

./my_package/test.py

for term in (u"ham", u"cooked", u"cheese", u"ice"):
    message = _(u"%s" % term, default="not translated")
    print term, message, pl_obj.translate(message)

output

ham ham prosciutto
cooked cooked not translated
cheese cheese not translated
ice ice not translated

however, if I add msgctxt "" in the "cheese" term

msgctxt ""
msgid "cheese"
msgstr "formaggio"

output

ham ham prosciutto
cooked cooked not translated
cheese cheese formaggio
ice ice ghiaccio
1 Like

Plone Foundation Code of Conduct