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