Comments for translators do not appear if the translatable string is after an indentation
|Reported by:||ygbo||Owned by:||nott|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I noticed this issue where the comment for translators does not appear in po files, it might also be a documentation clarification need to be added in:
A small example is shorter than a long explanation:
# Translators: This doesn't work ungettext_lazy( "singular example 1", "plural example 1", count ) # Translators: This works ungettext_lazy("singular example 2", "plural example 2", count) # Translators: This works too ungettext_lazy("singular example 3", "plural example 3", count)
in my po file I see this:
#: tables/actions.py:652 msgid "singular example 1" msgid_plural "plural example 1" msgstr "" msgstr "" #. Translators: This works #: tables/actions.py:657 msgid "singular example 2" msgid_plural "plural example 2" msgstr "" msgstr "" #. Translators: This works too #: tables/actions.py:659 msgid "singular example 3" msgid_plural "plural example 3" msgstr "" msgstr ""
The issue is the same with all *gettext(_lazy) functions.
As you can see the "#. Translators: This doesn't works" comment doesn't appear in the po file after running django_admin makemessages.
I know that in the doc it says that the comment needs to be preceding the string.
But it also needs to be preceding the *gettext(_lazy) function call with the string on the same line too.
When you really need indentation (for pep8 and/or flake8 reasons) comments can't be used inside the function.
In the example bellow the comment doesn't appear in the po file either, while it is well preceding the string (but inside the call to the gettext function instead of preceding it too):
ungettext_lazy( # Translators: This doesn't work either "singular example 1", "plural example 1", count )
If it's a gettext issue, It could be worth mentioning it in the documentation.
In fact the comment has to be preceding both the translation function and the string, and the string has to be on the same line as the function call, if we want the comment to appear in the po file.
It isn't a big issue for pgettext because translators have the contextual marker to help them, but it is for the other methods.
Change History (3)
comment:1 Changed 3 years ago by
|Component:||Uncategorized → Internationalization|
|Triage Stage:||Unreviewed → Accepted|
|Type:||Uncategorized → Bug|