Merge pull request #20093 from larssandergreen/mailings-AB-test-improvements
[civicrm-core.git] / CRM / Core / I18n / NativeGettext.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 * Convenience class for PHP-Gettext compatibility.
17 */
18class CRM_Core_I18n_NativeGettext {
518fa0ee 19
a0ee3941 20 /**
a2f24340 21 * @param string $string
a0ee3941
EM
22 *
23 * @return string
24 */
00be9182 25 public function translate($string) {
6a488035
TO
26 return gettext($string);
27 }
28
29 /**
30 * Based on php-gettext, since native gettext does not support this as is.
7a9ab499 31 *
a2f24340
BT
32 * @param string $context
33 * @param string $text
7a9ab499
EM
34 *
35 * @return string
6a488035 36 */
00be9182 37 public function pgettext($context, $text) {
6a488035
TO
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
a0ee3941 49 /**
a2f24340
BT
50 * @param string $text
51 * @param string $plural
52 * @param int $count
a0ee3941
EM
53 *
54 * @return string
55 */
00be9182 56 public function ngettext($text, $plural, $count) {
6a488035
TO
57 return ngettext($text, $plural, $count);
58 }
96025800 59
6a488035 60}