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: -
Votes:24
Avg. Score:4.3 ± 0.9
Reproduced:20 of 20 (100.0%)
Same Version:7 (35.0%)
Same OS:3 (15.0%)
From: jani dot ollikainen at pronetko dot fi Assigned:
Status: Open 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);
	}
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jul 10 13:01:25 2020 UTC