Merge pull request #17346 from eileenmcnaughton/trans2
[civicrm-core.git] / CRM / Core / I18n / NativeGettext.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 *
17 * Convenience class for PHP-Gettext compatibility.
18 */
19 class CRM_Core_I18n_NativeGettext {
20
21 /**
22 * @param $string
23 *
24 * @return string
25 */
26 public function translate($string) {
27 return gettext($string);
28 }
29
30 /**
31 * Based on php-gettext, since native gettext does not support this as is.
32 *
33 * @param $context
34 * @param $text
35 *
36 * @return string
37 */
38 public function pgettext($context, $text) {
39 $key = $context . chr(4) . $text;
40 $ret = $this->translate($key);
41
42 if (strpos($ret, "\004") !== FALSE) {
43 return $text;
44 }
45 else {
46 return $ret;
47 }
48 }
49
50 /**
51 * @param $text
52 * @param $plural
53 * @param $count
54 *
55 * @return string
56 */
57 public function ngettext($text, $plural, $count) {
58 return ngettext($text, $plural, $count);
59 }
60
61 }