﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22578	Comments for translators do not appear if the translatable string is after an indentation	ygbo	nott	"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."	Bug	closed	Internationalization	1.6	Normal	wontfix			Accepted	0	0	0	0	0	0
