php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51285 pgettext() and variants support for PHP
Submitted: 2010-03-12 14:56 UTC Modified: 2021-01-25 12:01 UTC
Votes:26
Avg. Score:4.3 ± 1.0
Reproduced:22 of 22 (100.0%)
Same Version:8 (36.4%)
Same OS:4 (18.2%)
From: jani dot ollikainen at pronetko dot fi Assigned: cmb (profile)
Status: Wont fix Package: Gettext related
PHP Version: 5.3.2 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-03-12 14:56 UTC] jani dot ollikainen at pronetko dot fi
Description:
------------
Newer gettext libraries provide Contexts to translate words that could
be need context based translation in other languages.

http://www.gnu.org/software/gettext/manual/gettext.html#Contexts

PHP's gettext library doesn't support those.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-12 12:26 UTC] n dot oxyde at gmail dot com
You don't need builtin support of pcontext() functions to use Gettext contexts.

1/ Define the functions yourself:

	function pgettext($context, $message)
	{
		return gettext($actual_message);
	}

	function dpgettext($domain, $context, $message)
	{
		$actual_message = $context . "\04" . $message;
		return dgettext($domain, $actual_message);
	}

	function dcpgettext($domain, $context, $message, $category)
	{
		$actual_message = $context . "\04" . $message;
		return dcgettext($domain, $actual_message, $category);
	}

	function npgettext($context, $msgid1, $msgid2, $n)
	{
		$actual_msgid1 = $context . "\04" . $msgid1;
		$actual_msgid2 = $context . "\04" . $msgid2;
		return ngettext($actual_msgid1, $actual_msgid2, $n);
	}

	function dnpgettext($domain, $context, $msgid1, $msgid2, $n)
	{
		$actual_msgid1 = $context . "\04" . $msgid1;
		$actual_msgid2 = $context . "\04" . $msgid2;
		return dngettext($domain, $actual_msgid1, $actual_msgid2, $n);
	}

	function dcnpgettext(
		$domain, $context, $msgid1, $msgid2, $n, $category)
	{
		$actual_msgid1 = $context . "\04" . $msgid1;
		$actual_msgid2 = $context . "\04" . $msgid2;
		return dcngettext(
			$domain, $actual_msgid1, $actual_msgid2, $n, $category);
	}

2/ Pass additional keywords arguments to xgettext:

	xgettext \
		-kpgettext:1c,2 \
		-kdpgettext:2c,3 \
		-kdcpgettext:2c,3 \
		-knpgettext:1c,2,3 \
		-kdnpgettext:2c,3,4 \
		-kdcnpgettext:2c,3,4
 [2014-08-28 07:39 UTC] PhoneixSegovia at gmail dot com
The problem with user implementations is that when a translation isn't found, the cryptic message is returned (the union of context and message). And this why in gettext you use the message as identifier (among other things).

To give full support to gettext, pgettext variant must be implemented, and is an important flag if not implemented, why gettext implemented it if not?

Also, I think that n.oxyde definition of

	function pgettext($context, $message)
	{
		return gettext($actual_message);
	}

Must really be:


	function pgettext($context, $message)
	{
		$actual_message = $context . "\04" . $message;
		return gettext($actual_message);
	}
 [2021-01-25 12:01 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-01-25 12:01 UTC] cmb@php.net
> The problem with user implementations is that when a translation
> isn't found, the cryptic message is returned (the union of context
> and message).

This is why you should compare the return value of gettext() and
friends in the pgettext() wrappers.  If it is identical to the
context, just return the message ID.  That is exactly how
pgettext() and friends are implemented in GNU libintl.

I don't see the need to implement these functions in ext/gettext.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 16 22:03:34 2021 UTC