classification
Title: Add gettext.pgettext() and variants support
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: loewis Nosy List: AndrewZiem, Felix Schwarz, Flimm, bernie, bersace, bronger, cito, clouserw, dns, dwayne, eric.araujo, franz_glasner, genepi, loewis, mitar, nh2, nhooey, nils, olivier-berten, sascha_silbe, wichert
Priority: normal Keywords: patch

Created on 2008-03-29 02:10 by genepi, last changed 2014-11-03 14:56 by eric.araujo.

Files
File name Uploaded Description Edit
gettext-pgettext.patch franz_glasner, 2008-04-15 20:17 Patch for gettext module to add pgettext and variants review
pgettext-3.2.diff eric.araujo, 2010-11-26 05:28
Messages (20)
msg64675 - (view) Author: Pierre Metras (genepi) Date: 2008-03-29 02:10
Please add support for pgettext(msgctxt, msgid) and variants (dpgettext,
dcpgettext...) in the gettext module.

I will not rephrase the justification for these functions and why
contexts are essential for good localization:
http://www.gnu.org/software/gettext/manual/gettext.html#Contexts
msg64685 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-03-29 08:38
Would you like to work on a patch?
msg65526 - (view) Author: Franz Glasner (franz_glasner) Date: 2008-04-15 20:17
I have written a patch against the current Python trunk's gettext to
add support for pgettext and friends (upgettext, npgettext, unpgettext,
...).

I have also changed Tools/i18n/msgfmt.py to recognize the "msgctxt" keyword.
Some new unittests for dgettext and lgettext and variants are also included.

If the patch will be accepted then someone should drop a message to the
maintainers of GNU gettext to add the new functions as default keywords
for xgettext. Right now you have to call xgettext with
"--keyword=pgettext:1c,2" to extract messages with context. 

Tools/i18n/pygettext.py does currently not handle context variants.
msg79609 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2009-01-11 18:57
I don't see any change in Modules/_localemodule.c: you reimplemented 
pgettext() in pure Python. Why no reusing existing pgettext() function 
(at least when it's present)?
msg79610 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-11 19:00
The gettext module is intentionally written in pure Python; it should
stay that way. Whether or not the _locale module should also grow
support for pgettext is a different issue.
msg90338 - (view) Author: David Schnur (dns) Date: 2009-07-09 18:14
I came across this ticket while looking for alternatives to Python's
gettext, since I need msgctx support.  It seems a patch was supplied for
this a while back.  I have never contributed to Python, and am not
familiar with your release process, but is there anything preventing its
inclusion?  It would be very convenient to have this in a release version.
msg90339 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-07-09 18:31
Only my lack of time prevents inclusion.
msg91472 - (view) Author: Mitar (mitar) Date: 2009-08-11 09:56
I would just like to add that I am also looking forwards to this feature.
msg92796 - (view) Author: (nh2) Date: 2009-09-17 21:19
Me too. This makes developing applications with good localizations in
Python really difficult.
msg97788 - (view) Author: David D Lowe (Flimm) Date: 2010-01-14 21:18
Same here.
msg105126 - (view) Author: Olivier Berten (olivier-berten) Date: 2010-05-06 06:49
Pleeeeeeeaaaaaaaase ;-)
msg106121 - (view) Author: Bernie H. Innocenti (bernie) Date: 2010-05-20 00:07
While we're waiting for this patch to be upstreamed, what's the best way to emulate this functionality with the current gettext module?

I'm looking at the patch and it seems that code similar to this might work?

  def pgettext(ctx, msg):
     return gettext(ctx + "\x04" + msg)
msg106132 - (view) Author: Wil Clouser (clouserw) Date: 2010-05-20 04:47
Yes.  You can see an in-production implementation at http://github.com/clouserw/tower/blob/master/tower/__init__.py#L51 (I'm overriding ugettext to support an optional context).
msg106709 - (view) Author: Wichert Akkerman (wichert) Date: 2010-05-29 06:39
Martin, is there anything we can do to help get this merged? I can really use this as well.

My background here is that currently the complete zope i18n support abuses message ids as a workaround, and the result works but is very painful for translators since the original string is not immediately visible for them.
msg107560 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-11 16:44
The patch needs to be updated for the 3.x trunk (py3k branch), since the last 2.x version is already rc.

Everyone, thanks for expressing interest for the development of Python, but posting “me too” messages does not further the discussion, and actually takes time from already busy people. Use cases, patches, reviews and the occasional bump (one is enough) are helpful. :)
msg122439 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-26 05:28
I have ported the patch to py3k, without tests errors but with test failures.  What is left to do:

1) Carefully assess bytes/str issues.  Decide to change the tests or the code.

2) Re-read over the new docs.

3) Exercise the updated msgfmt.py tool, which has no tests.

4) Add support in pygettext.py.

David, Mitar, nh2, David D., Olivier, Bernie, Wil, Wichert: Do you want to help with one of those tasks?
msg122446 - (view) Author: Wichert Akkerman (wichert) Date: 2010-11-26 09:20
I can help test changes for python 2.x. The python 3.x ecosystem is at least a year away from becoming interesting for me I'm afraid.
msg122482 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-26 23:13
New features don’t go into stable branches.

The patch is also reviewable at http://codereview.appspot.com/3340041
msg202189 - (view) Author: Neil Hooey (nhooey) Date: 2013-11-05 03:13
Can someone review the patch and consider its inclusion?
msg230537 - (view) Author: Wichert Akkerman (wichert) Date: 2014-11-03 14:49
Bump.

Python 3 is still not on my radar, but I'll happily do a backport for Py2 and drop that on PyPI once this gets resolved.
History
Date User Action Args
2014-11-03 14:56:08eric.araujosetstage: patch review -> needs patch
versions: - Python 3.2, Python 3.3, Python 3.4, Python 3.6
2014-11-03 14:49:41wichertsetmessages: + msg230537
versions: + Python 3.3, Python 3.4, Python 3.5, Python 3.6
2013-11-05 03:13:03nhooeysetnosy: + nhooey
messages: + msg202189
2011-02-11 17:28:31sascha_silbesetnosy: + sascha_silbe
2011-01-31 19:15:02bersacesetnosy: + Felix Schwarz
2011-01-31 19:14:36bersacesetnosy: + bersace
2011-01-31 19:14:17bersacesetnosy: - Felix Schwarz
2010-12-26 17:05:45Felix Schwarzsetnosy: + Felix Schwarz
2010-11-26 23:13:57eric.araujosetmessages: + msg122482
2010-11-26 09:20:22wichertsetmessages: + msg122446
2010-11-26 05:28:48eric.araujosetfiles: + pgettext-3.2.diff
resolution: accepted ->
messages: + msg122439

stage: needs patch -> patch review
2010-06-29 12:42:28eric.araujosetresolution: accepted
stage: needs patch
2010-06-15 15:25:41nilssetnosy: + nils
2010-06-11 16:44:09eric.araujosetnosy: + eric.araujo
messages: + msg107560
2010-05-29 06:39:49wichertsetnosy: + wichert
messages: + msg106709
2010-05-20 04:47:21clouserwsetmessages: + msg106132
2010-05-20 00:07:17berniesetnosy: + bernie
messages: + msg106121
2010-05-06 06:56:14loewissetversions: + Python 3.2, - Python 2.6, Python 3.0
2010-05-06 06:49:23olivier-bertensetnosy: + olivier-berten
messages: + msg105126
2010-01-14 21:18:26Flimmsetnosy: + Flimm
messages: + msg97788
2009-12-02 21:29:04clouserwsetnosy: + clouserw
2009-10-24 19:29:56AndrewZiemsetnosy: + AndrewZiem
2009-09-20 18:47:00citosetnosy: + cito
2009-09-17 21:19:32nh2setnosy: + nh2
messages: + msg92796
2009-08-11 09:56:19mitarsetnosy: + mitar
messages: + msg91472
2009-07-09 18:31:24loewissetmessages: + msg90339
2009-07-09 18:14:21dnssetnosy: + dns
messages: + msg90338
2009-03-24 23:07:27hayposetnosy: - haypo
2009-01-11 19:00:36loewissetmessages: + msg79610
2009-01-11 18:57:45hayposetnosy: + haypo
messages: + msg79609
2009-01-11 12:25:13dwaynesetnosy: + dwayne
2008-05-03 10:22:28brongersetnosy: + bronger
2008-04-15 21:17:01loewissetassignee: loewis
2008-04-15 20:17:20franz_glasnersetfiles: + gettext-pgettext.patch
nosy: + franz_glasner
keywords: + patch
messages: + msg65526
components: + Library (Lib), - Extension Modules
2008-03-29 08:38:24loewissetnosy: + loewis
messages: + msg64685
2008-03-29 02:10:23genepicreate