-
Notifications
You must be signed in to change notification settings - Fork 5
/
pgettext.php
45 lines (38 loc) · 1.44 KB
/
pgettext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/* These functions are related to the normal gettext functions except that they are
* taking an context variable as well */
function pgettext($msg_ctxt, $msgid) {
return dpgettext(textdomain(null), $msg_ctxt, $msgid);
}
function dpgettext($domain, $msg_ctxt, $msgid) {
return dcpgettext($domain, $msg_ctxt, $msgid, LC_MESSAGES);
}
function dcpgettext($domain, $msg_ctxt, $msgid, $category) {
$msg_ctxt_id = "{$msg_ctxt}\004{$msgid}";
$translation = dcgettext( $domain, $msg_ctxt_id, $category);
if( $translation == $msg_ctxt_id ) {
return $msgid;
} else {
return $translation;
}
}
function npgettext($msg_ctxt, $msgid, $msgid_plural, $n) {
return dnpgettext(textdomain(null), $msg_ctxt, $msgid, $msgid_plural, $n);
}
function dnpgettext($domain, $msg_ctxt, $msgid, $msgid_plural, $n) {
return dcnpgettext($domain, $msg_ctxt, $msgid, $msgid_plural, $n, LC_MESSAGES);
}
function dcnpgettext($domain, $msg_ctxt, $msgid, $msgid_plural, $n, $category) {
$msg_ctxt_id = "{$msg_ctxt}\004{$msgid}";
$translation = dcngettext( $domain, $msg_ctxt_id, $msgid_plural, $n, $category);
if( $translation == $msg_ctxt_id || $translation == $msgid_plural ) {
return $n == 1 ? $msgid : $msgid_plural;
} else {
return $translation;
}
}
/* PHP also lacks gettext_noop; Even though this isn't an simple macro expansion as
* it is in the c code, I assume it won't affect the performance much when used. */
function gettext_noop($msgid) {
return $msgid;
}