Opened 2 years ago

Closed 2 years ago

#22578 closed Bug (wontfix)

Comments for translators do not appear if the translatable string is after an indentation

Reported by: ygbo Owned by: nott
Component: Internationalization Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: 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
    "singular example 1",
    "plural example 1",
# Translators: This works
ungettext_lazy("singular example 2", "plural example 2", count)
# Translators: This works too
ungettext_lazy("singular example 3",
               "plural example 3",

in my po file I see this:

#: tables/                                                        
msgid "singular example 1"                                                      
msgid_plural "plural example 1"                                                 
msgstr[0] ""                                                                    
msgstr[1] ""                                                                    
#. Translators: This works                                                      
#: tables/                                                        
msgid "singular example 2"                                                      
msgid_plural "plural example 2"                                                 
msgstr[0] ""                                                                    
msgstr[1] ""                                                                    
#. Translators: This works too                                                  
#: tables/                                                        
msgid "singular example 3"                                                      
msgid_plural "plural example 3"                                                 
msgstr[0] ""                                                                    
msgstr[1] ""

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):

    # Translators: This doesn't work either
    "singular example 1",
    "plural example 1",

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 2 years ago by bmispelon

  • Component changed from Uncategorized to Internationalization
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug


I agree that this is an issue and I can reproduce this.

I'm not too familiar with that part of the codebase but my gut feeling is that we should try and fix this in the code if possible and only document it if the fix would be too complicated.


comment:2 Changed 2 years ago by nott

  • Owner changed from nobody to nott
  • Status changed from new to assigned

comment:3 Changed 2 years ago by nott

  • Resolution set to wontfix
  • Status changed from assigned to closed

looks like it's a gettext bug

makemessages just calls xgettext - an executable from gettext project

Note: See TracTickets for help on using tickets.
Back to Top