Test Failed
Push — master ( 647c72...cd42b5 )
by
unknown
10:25
created

server/includes/gettext.php (1 issue)

1
<?php
2
/*
3
 * Implementation of the missing (context) gettext functionalities in PHP. The
4
 * character \004 is used as glue to be able to use contexts in our translations.
5
 */
6
if (!function_exists('pgettext')) {
7
	/**
8
	 * Gettext function.
9
	 * @param $msgctxt {string} The Context
10
	 * @param $msgid {string} The message
11
	 * @return {string} The translation
12
	 */
13
	function pgettext($msgctxt, $msgid) {
14
		$contextString = "{$msgctxt}\004{$msgid}";
15
		$translation = _($contextString);
16
		if($translation == $contextString){
17
			return $msgid;
18
		} else {
19
			return $translation;
20
		}
21
	}
22
	/**
23
	 * Gettext function.
24
	 * @param $msgctxt {string} The Context
25
	 * @param $msgid {string} The message
26
	 * @param $msgid_plural {string} The plural text
27
	 * @param $num {Number} The count
28
	 * @return {string} The translation
29
	 */
30
	function npgettext($msgctxt, $msgid, $msgid_plural, $num) {
31
		$contextString = "{$msgctxt}\004{$msgid}";
32
		$contextStringPlural = "{$msgctxt}\004{$msgid_plural}";
33
		$translation = ngettext($contextString, $contextStringPlural, $num);
34
		if($translation == $contextString || $translation == $contextStringPlural){
35
			return $msgid;
36
		} else {
37
			return $translation;
38
		}
39
	}
40
	/**
41
	 * Gettext function.
42
	 * @param $domain {string} The Domain
43
	 * @param $msgctxt {string} The Context
44
	 * @param $msgid {string} The message
45
	 * @return {string} The translation
46
	 */
47
	function dpgettext($domain, $msgctxt, $msgid){
48
		$contextString = "{$msgctxt}\004{$msgid}";
49
		$translation = dcgettext($domain, $contextString, LC_MESSAGES);
50
		if($translation == $contextString){
51
			return $msgid;
52
		}else{
53
			return $translation;
54
		}
55
	}
56
	/**
57
	 * Gettext function.
58
	 * @param $domain {string} The Domain
59
	 * @param $msgctxt {string} The Context
60
	 * @param $msgid {string} The message
61
	 * @param $category {Number} The category
62
	 * @return {string} The translation
63
	 */
64
	function dcpgettext($domain, $msgctxt, $msgid, $category){
65
		$contextString = "{$msgctxt}\004{$msgid}";
66
		$translation = dcgettext($domain, $contextString, $category);
67
		if($translation == $contextString){
68
			return $msgid;
69
		}else{
70
			return $translation;
71
		}
72
	}
73
}
74
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
75