CRM-13823 - Add php version check
[civicrm-core.git] / CRM / Core / I18n.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33class CRM_Core_I18n {
34
07844ccf
SV
35 /**
36 * Constants for communication preferences.
37 *
38 * @var int
39 */
40 const NONE = 'none', AUTO = 'auto';
41
42
6a488035 43 /**
2ba175b6
DL
44 * A PHP-gettext instance for string translation;
45 * should stay null if the strings are not to be translated (en_US).
6a488035
TO
46 */
47 private $_phpgettext = NULL;
48
49 /**
50 * Whether we are using native gettext or not.
51 */
52 private $_nativegettext = FALSE;
53
74eb462f
ML
54 /**
55 * Gettext cache for extension domains/streamers, depending on if native or phpgettext.
56 * - native gettext: we cache the value for textdomain()
57 * - phpgettext: we cache the file streamer.
58 */
59 private $_extensioncache = array();
60
0d096477
TO
61 /**
62 * @var string
63 */
64 private $locale;
65
6a488035
TO
66 /**
67 * A locale-based constructor that shouldn't be called from outside of this class (use singleton() instead).
68 *
5a4f6742
CW
69 * @param string $locale
70 * the base of this certain object's existence.
6a488035 71 *
77b97be7 72 * @return \CRM_Core_I18n
6a488035 73 */
00be9182 74 public function __construct($locale) {
0d096477 75 $this->locale = $locale;
6a488035 76 if ($locale != '' and $locale != 'en_US') {
6a488035
TO
77 if (defined('CIVICRM_GETTEXT_NATIVE') && CIVICRM_GETTEXT_NATIVE && function_exists('gettext')) {
78 // Note: the file hierarchy for .po must be, for example: l10n/fr_FR/LC_MESSAGES/civicrm.mo
79
80 $this->_nativegettext = TRUE;
81
82 $locale .= '.utf8';
83 putenv("LANG=$locale");
84
85 // CRM-11833 Avoid LC_ALL because of LC_NUMERIC and potential DB error.
86 setlocale(LC_TIME, $locale);
87 setlocale(LC_MESSAGES, $locale);
88 setlocale(LC_CTYPE, $locale);
89
4d8ce7f0 90 bindtextdomain('civicrm', CRM_Core_I18n::getResourceDir());
6a488035
TO
91 bind_textdomain_codeset('civicrm', 'UTF-8');
92 textdomain('civicrm');
93
94 $this->_phpgettext = new CRM_Core_I18n_NativeGettext();
74eb462f 95 $this->_extensioncache['civicrm'] = 'civicrm';
6a488035
TO
96 return;
97 }
98
99 // Otherwise, use PHP-gettext
b395e3c0
ML
100 // we support both the old file hierarchy format and the new:
101 // pre-4.5: civicrm/l10n/xx_XX/civicrm.mo
102 // post-4.5: civicrm/l10n/xx_XX/LC_MESSAGES/civicrm.mo
6a488035
TO
103 require_once 'PHPgettext/streams.php';
104 require_once 'PHPgettext/gettext.php';
105
4d8ce7f0 106 $mo_file = CRM_Core_I18n::getResourceDir() . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . 'civicrm.mo';
b395e3c0 107
353ffa53 108 if (!file_exists($mo_file)) {
b395e3c0 109 // fallback to pre-4.5 mode
4d8ce7f0 110 $mo_file = CRM_Core_I18n::getResourceDir() . $locale . DIRECTORY_SEPARATOR . 'civicrm.mo';
b395e3c0
ML
111 }
112
113 $streamer = new FileReader($mo_file);
6a488035 114 $this->_phpgettext = new gettext_reader($streamer);
74eb462f 115 $this->_extensioncache['civicrm'] = $this->_phpgettext;
6a488035
TO
116 }
117 }
118
119 /**
120 * Returns whether gettext is running natively or using PHP-Gettext.
121 *
a6c01b45
CW
122 * @return bool
123 * True if gettext is native
6a488035 124 */
00be9182 125 public function isNative() {
6a488035
TO
126 return $this->_nativegettext;
127 }
128
129 /**
130 * Return languages available in this instance of CiviCRM.
131 *
5a4f6742
CW
132 * @param bool $justEnabled
133 * whether to return all languages or just the enabled ones.
6a488035 134 *
a6c01b45 135 * @return array
16b10e64 136 * Array of code/language name mappings
6a488035 137 */
00be9182 138 public static function languages($justEnabled = FALSE) {
6a488035
TO
139 static $all = NULL;
140 static $enabled = NULL;
141
142 if (!$all) {
c0c9cd82 143 $all = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
6a488035
TO
144
145 // check which ones are available; add them to $all if not there already
6a488035 146 $codes = array();
4d8ce7f0 147 if (is_dir(CRM_Core_I18n::getResourceDir()) && $dir = opendir(CRM_Core_I18n::getResourceDir())) {
6a488035
TO
148 while ($filename = readdir($dir)) {
149 if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
150 $codes[] = $filename;
151 if (!isset($all[$filename])) {
152 $all[$filename] = $filename;
153 }
154 }
155 }
156 closedir($dir);
157 }
158
159 // drop the unavailable languages (except en_US)
160 foreach (array_keys($all) as $code) {
161 if ($code == 'en_US') {
162 continue;
163 }
408b79bf 164 if (!in_array($code, $codes)) {
165 unset($all[$code]);
166 }
6a488035
TO
167 }
168 }
169
170 if ($enabled === NULL) {
171 $config = CRM_Core_Config::singleton();
172 $enabled = array();
173 if (isset($config->languageLimit) and $config->languageLimit) {
174 foreach ($all as $code => $name) {
175 if (in_array($code, array_keys($config->languageLimit))) {
176 $enabled[$code] = $name;
177 }
178 }
179 }
180 }
181
182 return $justEnabled ? $enabled : $all;
183 }
184
185 /**
186 * Replace arguments in a string with their values. Arguments are represented by % followed by their number.
187 *
5a4f6742
CW
188 * @param string $str
189 * source string.
6a488035 190 *
a6c01b45
CW
191 * @return string
192 * modified string
6a488035 193 */
00be9182 194 public function strarg($str) {
6a488035
TO
195 $tr = array();
196 $p = 0;
197 for ($i = 1; $i < func_num_args(); $i++) {
198 $arg = func_get_arg($i);
199 if (is_array($arg)) {
200 foreach ($arg as $aarg) {
201 $tr['%' . ++$p] = $aarg;
202 }
203 }
204 else {
205 $tr['%' . ++$p] = $arg;
206 }
207 }
208 return strtr($str, $tr);
209 }
210
4d8ce7f0
TO
211 public static function getResourceDir() {
212 static $dir = NULL;
213 if ($dir === NULL) {
214 $dir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR;
215 }
216 return $dir;
217 }
218
6a488035
TO
219 /**
220 * Smarty block function, provides gettext support for smarty.
221 *
222 * The block content is the text that should be translated.
223 *
224 * Any parameter that is sent to the function will be represented as %n in the translation text,
225 * where n is 1 for the first parameter. The following parameters are reserved:
226 * - escape - sets escape mode:
227 * - 'html' for HTML escaping, this is the default.
228 * - 'js' for javascript escaping.
229 * - 'no'/'off'/0 - turns off escaping
230 * - plural - The plural version of the text (2nd parameter of ngettext())
231 * - count - The item count for plural mode (3rd parameter of ngettext())
232 * - context - gettext context of that string (for homonym handling)
233 *
5a4f6742
CW
234 * @param string $text
235 * the original string.
236 * @param array $params
3f3bba82
TO
237 * The params of the translation (if any).
238 * - domain: string|array a list of translation domains to search (in order)
239 * - context: string
e3b7fc11 240 *
a6c01b45
CW
241 * @return string
242 * the translated string
6a488035 243 */
00be9182 244 public function crm_translate($text, $params = array()) {
6a488035
TO
245 if (isset($params['escape'])) {
246 $escape = $params['escape'];
247 unset($params['escape']);
248 }
249
250 // sometimes we need to {ts}-tag a string, but don’t want to
251 // translate it in the template (like civicrm_navigation.tpl),
252 // because we handle the translation in a different way (CRM-6998)
253 // in such cases we return early, only doing SQL/JS escaping
254 if (isset($params['skip']) and $params['skip']) {
255 if (isset($escape) and ($escape == 'sql')) {
74032946 256 $text = CRM_Core_DAO::escapeString($text);
6a488035
TO
257 }
258 if (isset($escape) and ($escape == 'js')) {
259 $text = addcslashes($text, "'");
260 }
261 return $text;
262 }
263
3f3bba82 264 $plural = $count = NULL;
6a488035
TO
265 if (isset($params['plural'])) {
266 $plural = $params['plural'];
267 unset($params['plural']);
268 if (isset($params['count'])) {
269 $count = $params['count'];
270 }
271 }
272
273 if (isset($params['context'])) {
274 $context = $params['context'];
275 unset($params['context']);
276 }
277 else {
278 $context = NULL;
279 }
280
3f3bba82
TO
281 if (isset($params['domain'])) {
282 $domain = $params['domain'];
283 unset($params['domain']);
284 }
285 else {
286 $domain = NULL;
287 }
288
1b4710da
TO
289 $raw = !empty($params['raw']);
290 unset($params['raw']);
291
3f3bba82
TO
292 if (!empty($domain)) {
293 // It might be prettier to cast to an array, but this is high-traffic stuff.
294 if (is_array($domain)) {
295 foreach ($domain as $d) {
296 $candidate = $this->crm_translate_raw($text, $d, $count, $plural, $context);
297 if ($candidate != $text) {
298 $text = $candidate;
299 break;
300 }
301 }
302 }
303 else {
304 $text = $this->crm_translate_raw($text, $domain, $count, $plural, $context);
305 }
306 }
307 else {
308 $text = $this->crm_translate_raw($text, NULL, $count, $plural, $context);
309 }
310
311 // replace the numbered %1, %2, etc. params if present
1b4710da 312 if (count($params) && !$raw) {
3f3bba82
TO
313 $text = $this->strarg($text, $params);
314 }
315
316 // escape SQL if we were asked for it
317 if (isset($escape) and ($escape == 'sql')) {
318 $text = CRM_Core_DAO::escapeString($text);
319 }
320
321 // escape for JavaScript (if requested)
322 if (isset($escape) and ($escape == 'js')) {
323 $text = addcslashes($text, "'");
324 }
325
326 return $text;
327 }
328
329 /**
330 * Lookup the raw translation of a string (without any extra escaping or interpolation).
331 *
332 * @param string $text
333 * @param string|NULL $domain
334 * @param int|NULL $count
335 * @param string $plural
336 * @param string $context
e3b7fc11 337 *
338 * @return string
3f3bba82
TO
339 */
340 protected function crm_translate_raw($text, $domain, $count, $plural, $context) {
1a3cba0e
ML
341 // gettext domain for extensions
342 $domain_changed = FALSE;
3f3bba82
TO
343 if (!empty($domain) && $this->_phpgettext) {
344 if ($this->setGettextDomain($domain)) {
1a3cba0e
ML
345 $domain_changed = TRUE;
346 }
347 }
348
6a488035 349 // do all wildcard translations first
0d096477
TO
350 if (!isset(Civi::$statics[__CLASS__][$this->locale])) {
351 if (defined('CIVICRM_DSN') && !CRM_Core_Config::isUpgradeMode()) {
352 Civi::$statics[__CLASS__][$this->locale] = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($this->locale);
234d8f09
TO
353 }
354 else {
0d096477 355 Civi::$statics[__CLASS__][$this->locale] = array();
234d8f09
TO
356 }
357 }
0d096477 358 $stringTable = Civi::$statics[__CLASS__][$this->locale];
6a488035
TO
359
360 $exactMatch = FALSE;
361 if (isset($stringTable['enabled']['exactMatch'])) {
362 foreach ($stringTable['enabled']['exactMatch'] as $search => $replace) {
363 if ($search === $text) {
364 $exactMatch = TRUE;
365 $text = $replace;
366 break;
367 }
368 }
369 }
370
6cf5bb6f
DL
371 if (
372 !$exactMatch &&
6a488035
TO
373 isset($stringTable['enabled']['wildcardMatch'])
374 ) {
353ffa53 375 $search = array_keys($stringTable['enabled']['wildcardMatch']);
6a488035 376 $replace = array_values($stringTable['enabled']['wildcardMatch']);
353ffa53 377 $text = str_replace($search, $replace, $text);
6a488035
TO
378 }
379
380 // dont translate if we've done exactMatch already
381 if (!$exactMatch) {
382 // use plural if required parameters are set
383 if (isset($count) && isset($plural)) {
384
385 if ($this->_phpgettext) {
386 $text = $this->_phpgettext->ngettext($text, $plural, $count);
387 }
388 else {
389 // if the locale's not set, we do ngettext work by hand
390 // if $count == 1 then $text = $text, else $text = $plural
391 if ($count != 1) {
392 $text = $plural;
393 }
394 }
395
396 // expand %count in translated string to $count
397 $text = strtr($text, array('%count' => $count));
398
399 // if not plural, but the locale's set, translate
400 }
401 elseif ($this->_phpgettext) {
402 if ($context) {
403 $text = $this->_phpgettext->pgettext($context, $text);
404 }
405 else {
406 $text = $this->_phpgettext->translate($text);
407 }
408 }
409 }
410
1a3cba0e
ML
411 if ($domain_changed) {
412 $this->setGettextDomain('civicrm');
413 }
414
6a488035
TO
415 return $text;
416 }
417
418 /**
419 * Translate a string to the current locale.
420 *
5a4f6742
CW
421 * @param string $string
422 * this string should be translated.
6a488035 423 *
a6c01b45
CW
424 * @return string
425 * the translated string
6a488035 426 */
00be9182 427 public function translate($string) {
6a488035
TO
428 return ($this->_phpgettext) ? $this->_phpgettext->translate($string) : $string;
429 }
430
431 /**
432 * Localize (destructively) array values.
433 *
5a4f6742
CW
434 * @param array $array
435 * the array for localization (in place).
436 * @param array $params
437 * an array of additional parameters.
6a488035 438 */
408b79bf 439 public function localizeArray(
6a488035
TO
440 &$array,
441 $params = array()
442 ) {
443 global $tsLocale;
444
445 if ($tsLocale == 'en_US') {
446 return;
447 }
448
449 foreach ($array as & $value) {
450 if ($value) {
451 $value = ts($value, $params);
452 }
453 }
454 }
455
456 /**
457 * Localize (destructively) array elements with keys of 'title'.
458 *
5a4f6742
CW
459 * @param array $array
460 * the array for localization (in place).
6a488035 461 */
00be9182 462 public function localizeTitles(&$array) {
6a488035
TO
463 foreach ($array as $key => $value) {
464 if (is_array($value)) {
465 $this->localizeTitles($value);
466 $array[$key] = $value;
467 }
468 elseif ((string ) $key == 'title') {
eb7d6f39 469 $array[$key] = ts($value, array('context' => 'menu'));
6a488035
TO
470 }
471 }
472 }
473
1a3cba0e
ML
474 /**
475 * Binds a gettext domain, wrapper over bindtextdomain().
476 *
6a0b768e
TO
477 * @param $key
478 * Key of the extension (can be 'civicrm', or 'org.example.foo').
1a3cba0e 479 *
408b79bf 480 * @return Bool
a6c01b45 481 * True if the domain was changed for an extension.
1a3cba0e 482 */
00be9182 483 public function setGettextDomain($key) {
82bcff63 484 /* No domain changes for en_US */
353ffa53 485 if (!$this->_phpgettext) {
82bcff63
ML
486 return FALSE;
487 }
1a3cba0e 488
74eb462f 489 // It's only necessary to find/bind once
353ffa53 490 if (!isset($this->_extensioncache[$key])) {
1a3cba0e
ML
491 try {
492 $mapper = CRM_Extension_System::singleton()->getMapper();
493 $path = $mapper->keyToBasePath($key);
494 $info = $mapper->keyToInfo($key);
495 $domain = $info->file;
496
74eb462f
ML
497 if ($this->_nativegettext) {
498 bindtextdomain($domain, $path . DIRECTORY_SEPARATOR . 'l10n');
499 bind_textdomain_codeset($domain, 'UTF-8');
500 $this->_extensioncache[$key] = $domain;
501 }
502 else {
503 // phpgettext
b52647df 504 $mo_file = $path . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR . $this->locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . $domain . '.mo';
74eb462f
ML
505 $streamer = new FileReader($mo_file);
506 $this->_extensioncache[$key] = new gettext_reader($streamer);
507 }
1a3cba0e
ML
508 }
509 catch (CRM_Extension_Exception $e) {
b44e3f84 510 // Intentionally not translating this string to avoid possible infinite loops
74eb462f
ML
511 // Only developers should see this string, if they made a mistake in their ts() usage.
512 CRM_Core_Session::setStatus('Unknown extension key in a translation string: ' . $key, '', 'error');
513 $this->_extensioncache[$key] = FALSE;
1a3cba0e
ML
514 }
515 }
516
74eb462f
ML
517 if (isset($this->_extensioncache[$key]) && $this->_extensioncache[$key]) {
518 if ($this->_nativegettext) {
519 textdomain($this->_extensioncache[$key]);
520 }
521 else {
522 $this->_phpgettext = $this->_extensioncache[$key];
523 }
524
525 return TRUE;
1a3cba0e 526 }
74eb462f
ML
527
528 return FALSE;
1a3cba0e
ML
529 }
530
07844ccf
SV
531
532 /**
533 * Is the CiviCRM in multilingual mode.
534 *
535 * @return Bool
536 * True if CiviCRM is in multilingual mode.
537 */
538 public static function isMultilingual() {
539 $domain = new CRM_Core_DAO_Domain();
540 $domain->find(TRUE);
541 return (bool) $domain->locales;
542 }
543
07844ccf
SV
544
545 /**
546 * Change the processing language without changing the current user language
547 *
548 * @param $language
549 * Language (for example 'en_US', or 'fr_CA').
550 * True if the domain was changed for an extension.
551 */
fd1f3a26 552 public function setLocale($language) {
aeb3ba30 553
07844ccf 554 $config = CRM_Core_Config::singleton();
fd1f3a26
SV
555
556 // Change the language of the CMS as well, for URLs.
557 CRM_Utils_System::setUFLocale($language);
558
559 // change the gettext ressources
07844ccf
SV
560 if ($this->_nativegettext) {
561 $locale = $language . '.utf8';
562 putenv("LANG=$locale");
563
564 setlocale(LC_TIME, $locale);
565 setlocale(LC_MESSAGES, $locale);
566 setlocale(LC_CTYPE, $locale);
567
568 bindtextdomain('civicrm', $config->gettextResourceDir);
569 bind_textdomain_codeset('civicrm', 'UTF-8');
570 textdomain('civicrm');
571
572 $this->_phpgettext = new CRM_Core_I18n_NativeGettext();
573 $this->_extensioncache['civicrm'] = 'civicrm';
574 }
575 else {
576 // phpgettext
577 require_once 'PHPgettext/streams.php';
578 require_once 'PHPgettext/gettext.php';
579
580 $mo_file = $config->gettextResourceDir . $language . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . 'civicrm.mo';
581
582 $streamer = new FileReader($mo_file);
583 $this->_phpgettext = new gettext_reader($streamer);
584 $this->_extensioncache['civicrm'] = $this->_phpgettext;
585
586 }
587
588 // for sql queries
589 global $dbLocale;
590 $dbLocale = "_{$language}";
591
592 }
593
6a488035
TO
594 /**
595 * Static instance provider - return the instance for the current locale.
c4c311c1
CW
596 *
597 * @return CRM_Core_I18n
6a488035 598 */
00be9182 599 public static function &singleton() {
6a488035
TO
600 static $singleton = array();
601
602 global $tsLocale;
603 if (!isset($singleton[$tsLocale])) {
604 $singleton[$tsLocale] = new CRM_Core_I18n($tsLocale);
605 }
606
607 return $singleton[$tsLocale];
608 }
609
610 /**
611 * Set the LC_TIME locale if it's not set already (for a given language choice).
612 *
a6c01b45
CW
613 * @return string
614 * the final LC_TIME that got set
6a488035 615 */
00be9182 616 public static function setLcTime() {
6a488035
TO
617 static $locales = array();
618
619 global $tsLocale;
620 if (!isset($locales[$tsLocale])) {
621 // with the config being set to pl_PL: try pl_PL.UTF-8,
622 // then pl_PL, if neither present fall back to C
623 $locales[$tsLocale] = setlocale(LC_TIME, $tsLocale . '.UTF-8', $tsLocale, 'C');
624 }
625
626 return $locales[$tsLocale];
627 }
96025800 628
9747df8a 629 /**
630 * Get the default language for contacts where no language is provided.
631 *
632 * Note that NULL is a valid option so be careful with checking for empty etc.
633 *
634 * NULL would mean 'we don't know & we don't want to hazard a guess'.
635 *
636 * @return string
637 */
638 public static function getContactDefaultLanguage() {
639 $language = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'contact_default_language');
640 if ($language == 'undefined') {
641 return NULL;
642 }
643 if (empty($language) || $language === '*default*') {
644 $language = civicrm_api3('setting', 'getvalue', array(
645 'name' => 'lcMessages',
646 'group' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
647 ));
648 }
649 elseif ($language == 'current_site_language') {
650 global $tsLocale;
651 return $tsLocale;
652 }
653
654 return $language;
655 }
656
6a488035
TO
657}
658
659/**
660 * Short-named function for string translation, defined in global scope so it's available everywhere.
661 *
e3b7fc11 662 * @param string $text
6a0b768e 663 * String string for translating.
16b10e64 664 * @param array $params
6a0b768e 665 * Array an array of additional parameters.
6a488035 666 *
a6c01b45 667 * @return string
353ffa53 668 * the translated string
6a488035
TO
669 */
670function ts($text, $params = array()) {
671 static $config = NULL;
672 static $locale = NULL;
673 static $i18n = NULL;
674 static $function = NULL;
675
676 if ($text == '') {
677 return '';
678 }
679
680 if (!$config) {
681 $config = CRM_Core_Config::singleton();
682 }
683
684 global $tsLocale;
685 if (!$i18n or $locale != $tsLocale) {
686 $i18n = CRM_Core_I18n::singleton();
687 $locale = $tsLocale;
688 if (isset($config->customTranslateFunction) and function_exists($config->customTranslateFunction)) {
689 $function = $config->customTranslateFunction;
690 }
691 }
692
693 if ($function) {
694 return $function($text, $params);
695 }
696 else {
697 return $i18n->crm_translate($text, $params);
698 }
699}