This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pygettext: extract translators comments
Type: enhancement Stage: needs patch
Components: Demos and Tools Versions: Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, eric.araujo, htrd
Priority: low Keywords: patch

Created on 2005-09-11 22:05 by htrd, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
pygettext.diff htrd, 2005-09-11 22:05 pygettext patch
Messages (4)
msg48728 - (view) Author: Toby Dickenson (htrd) Date: 2005-09-11 22:05
The .po file format supports "automatic comments". These are    
comments which have been automatically generated or extracted    
from the original source along with the "msgid" reference strings.    
    
Automatic comments are a good way to communicate extra   
information to the translator. For example message context, or  
information about string substitutions.  
  
The Gnu gettext tools have good support for "automatic  
comments". For example msgmerge (which merges updates  
from a programmer into the master po file maintained by a  
translator) will preserve the programmer's copy of the "automatic  
comments" but the translator's copy of the other comments.  
    
This patch includes an option to pygettext which automatically    
copies comments from Python source code into its output .po    
file. The comment must appear on the same line as the    
extracted string, and the first character of the comment    
(immediately after the #) must be a period.    
    
Example usage:    
    
msg = _('Opening file....') #. status bar message    
msg = _("Connected on %1") #. eg. connected on com1    
    
Rationale:    
    
Why not use any python source code comment on the same   
line, rather than require the #. prefix? My first variant of this patch   
worked that way. I found this inadvertently included too many   
programmer-oriented comments that were inappropriate for the    
translator.    
    
Why the #. notation? This is the same format as used in .po    
files. Thats not a big advantage, because nobody spends much 
time reading raw po files. It is concise, which is an advantage 
since the comment needs to be on the same line as the 
extracted string.    
    
Why should the python source code notation use python    
comments, rather than an extra parameter to the _    
function? Partly tradition.... Gnu gettext for C also looks in    
specially marked comments. It is also nice to not require    
changes to other translateable string extraction tools (if there are    
any) or existing translation functions which currently do not   
expect an extra parameter.   
    
Why a new command line option? Hmmmm - no good reason.....   
maybe this functionality should always be enabled.   
    
Why require the comment to be on the same line? Gnu gettext   
for C searches the same line *and* the preceeding line. I have   
experience converting a large python project of approx 800   
extracted strings where this hasnt been a problem. Im happy to   
extend this if necessary.   
   
   
   
    
    
msg107562 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-11 17:05
Translator comments seem to me nicer than contexts (http://bugs.python.org/issue2504), but I’m not sure which one is recommended when they overlap.

I’m -1 on the same line restriction. Python style is to put comments on the previous line.

The 2.x line does not accept new features, so your patch needs to be ported to 3.x (branch name py3k).

FWIW, Babel uses a different style of comments, on the preceding line: http://babel.edgewall.org/wiki/Documentation/messages.html#translator-comments
msg108903 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-29 12:55
It appears that I had mistaken comments in the source and comments in the pot/po files:

     /* TRANSLATORS: The placeholder indicates etc. */
     printf (_("Something.\n"));

These will be extracted by ‘xgettext’, leading to a .pot file that contains this:

     #. TRANSLATORS: The placeholder indicates etc.
     #: src/hello.c:178
     #, c-format
     msgid "Report bugs to <%s>.\n"
     msgstr ""


(From <http://www.gnu.org/software/gettext/manual/gettext.html>)
msg221642 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-26 20:23
Is there anything of value in the patch which can be used, as I can't comment on it from a technical viewpoint?  Otherwise can we close this as "out of date" or "won't fix" as appropriate?
History
Date User Action Args
2022-04-11 14:56:13adminsetgithub: 42361
2019-03-15 23:55:11BreamoreBoysetnosy: - BreamoreBoy
2014-06-26 20:23:22BreamoreBoysetnosy: + BreamoreBoy

messages: + msg221642
versions: + Python 3.4, Python 3.5, - Python 3.2
2010-10-25 19:34:20barrysetassignee: barry ->
2010-06-29 12:55:36eric.araujosettitle: pygettext: provide comments to help translators -> pygettext: extract translators comments
2010-06-29 12:55:11eric.araujosettitle: pygettext - provide comments to help translators -> pygettext: provide comments to help translators
stage: needs patch
messages: + msg108903
versions: + Python 3.2, - Python 2.6
2010-06-11 17:05:20eric.araujosetnosy: + eric.araujo
messages: + msg107562
2008-01-05 19:32:15christian.heimessetpriority: normal -> low
type: enhancement
versions: + Python 2.6
2005-09-11 22:05:19htrdcreate