Merge pull request #15820 from seamuslee001/dev_core_183_custom_contribsybnt
[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 * $Id$
17 *
18 * Convenience class for PHP-Gettext compatibility.
19 */
20 class CRM_Core_I18n_NativeGettext {
21
22 /**
23 * @param $string
24 *
25 * @return string
26 */
27 public function translate($string) {
28 return gettext($string);
29 }
30
31 /**
32 * Based on php-gettext, since native gettext does not support this as is.
33 *
34 * @param $context
35 * @param $text
36 *
37 * @return string
38 */
39 public function pgettext($context, $text) {
40 $key = $context . chr(4) . $text;
41 $ret = $this->translate($key);
42
43 if (strpos($ret, "\004") !== FALSE) {
44 return $text;
45 }
46 else {
47 return $ret;
48 }
49 }
50
51 /**
52 * @param $text
53 * @param $plural
54 * @param $count
55 *
56 * @return string
57 */
58 public function ngettext($text, $plural, $count) {
59 return ngettext($text, $plural, $count);
60 }
61
62 }