Opened 11 years ago

Closed 10 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

Description

Hi,

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:
https://docs.djangoproject.com/en/dev/topics/i18n/translation/#comments-for-translators

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[0] ""                                                                    
msgstr[1] ""                                                                    
                                                                                
#. Translators: This works                                                      
#: tables/actions.py:657                                                        
msgid "singular example 2"                                                      
msgid_plural "plural example 2"                                                 
msgstr[0] ""                                                                    
msgstr[1] ""                                                                    
                                                                                
#. Translators: This works too                                                  
#: tables/actions.py:659                                                        
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):

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.

Thanks.

Change History (3)

comment:1 by Baptiste Mispelon, 10 years ago

Component: UncategorizedInternationalization
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Hi,

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.

Thanks.

comment:2 by nott, 10 years ago

Owner: changed from nobody to nott
Status: newassigned

comment:3 by nott, 10 years ago

Resolution: wontfix
Status: assignedclosed

looks like it's a gettext bug

makemessages just calls xgettext - an executable from gettext project

https://savannah.gnu.org/bugs/index.php?42376

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