Merge pull request #14290 from MegaphoneJon/json-pp-logging
[civicrm-core.git] / CRM / Core / I18n.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33 class CRM_Core_I18n {
34
35 /**
36 * Constants for communication preferences.
37 *
38 * @var int
39 */
40 const NONE = 'none', AUTO = 'auto';
41
42 /**
43 * @var callable|null
44 * A callback function which handles SQL string encoding.
45 * Set NULL to use the default, CRM_Core_DAO::escapeString().
46 * This is used by `ts(..., [escape=>sql])`.
47 *
48 * This option is not intended for general consumption. It is only intended
49 * for certain pre-boot/pre-install contexts.
50 *
51 * You might ask, "Why on Earth does string-translation have an opinion on
52 * SQL escaping?" Good question!
53 */
54 public static $SQL_ESCAPER = NULL;
55
56 /**
57 * Encode a string for use in SQL.
58 *
59 * @param string $text
60 * @return string
61 */
62 protected static function escapeSql($text) {
63 if (self::$SQL_ESCAPER == NULL) {
64 return CRM_Core_DAO::escapeString($text);
65 }
66 else {
67 return call_user_func(self::$SQL_ESCAPER, $text);
68 }
69 }
70
71 /**
72 * A PHP-gettext instance for string translation;
73 * should stay null if the strings are not to be translated (en_US).
74 * @var object
75 */
76 private $_phpgettext = NULL;
77
78 /**
79 * Whether we are using native gettext or not.
80 * @var bool
81 */
82 private $_nativegettext = FALSE;
83
84 /**
85 * Gettext cache for extension domains/streamers, depending on if native or phpgettext.
86 * - native gettext: we cache the value for textdomain()
87 * - phpgettext: we cache the file streamer.
88 * @var array
89 */
90 private $_extensioncache = [];
91
92 /**
93 * @var string
94 */
95 private $locale;
96
97 /**
98 * A locale-based constructor that shouldn't be called from outside of this class (use singleton() instead).
99 *
100 * @param string $locale
101 * the base of this certain object's existence.
102 *
103 * @return \CRM_Core_I18n
104 */
105 public function __construct($locale) {
106 $this->locale = $locale;
107 if ($locale != '' and $locale != 'en_US') {
108 if (defined('CIVICRM_GETTEXT_NATIVE') && CIVICRM_GETTEXT_NATIVE && function_exists('gettext')) {
109 // Note: the file hierarchy for .po must be, for example: l10n/fr_FR/LC_MESSAGES/civicrm.mo
110
111 $this->_nativegettext = TRUE;
112 $this->setNativeGettextLocale($locale);
113 return;
114 }
115
116 // Otherwise, use PHP-gettext
117 $this->setPhpGettextLocale($locale);
118 }
119 }
120
121 /**
122 * Returns whether gettext is running natively or using PHP-Gettext.
123 *
124 * @return bool
125 * True if gettext is native
126 */
127 public function isNative() {
128 return $this->_nativegettext;
129 }
130
131 /**
132 * Set native locale for getText.
133 *
134 * @param string $locale
135 */
136 protected function setNativeGettextLocale($locale) {
137
138 $locale .= '.utf8';
139 putenv("LANG=$locale");
140
141 // CRM-11833 Avoid LC_ALL because of LC_NUMERIC and potential DB error.
142 setlocale(LC_TIME, $locale);
143 setlocale(LC_MESSAGES, $locale);
144 setlocale(LC_CTYPE, $locale);
145
146 bindtextdomain('civicrm', CRM_Core_I18n::getResourceDir());
147 bind_textdomain_codeset('civicrm', 'UTF-8');
148 textdomain('civicrm');
149
150 $this->_phpgettext = new CRM_Core_I18n_NativeGettext();
151 $this->_extensioncache['civicrm'] = 'civicrm';
152
153 }
154
155 /**
156 * Set getText locale.
157 *
158 * @param string $locale
159 */
160 protected function setPhpGettextLocale($locale) {
161
162 // we support both the old file hierarchy format and the new:
163 // pre-4.5: civicrm/l10n/xx_XX/civicrm.mo
164 // post-4.5: civicrm/l10n/xx_XX/LC_MESSAGES/civicrm.mo
165 require_once 'PHPgettext/streams.php';
166 require_once 'PHPgettext/gettext.php';
167
168 $mo_file = CRM_Core_I18n::getResourceDir() . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . 'civicrm.mo';
169
170 if (!file_exists($mo_file)) {
171 // fallback to pre-4.5 mode
172 $mo_file = CRM_Core_I18n::getResourceDir() . $locale . DIRECTORY_SEPARATOR . 'civicrm.mo';
173 }
174
175 $streamer = new FileReader($mo_file);
176 $this->_phpgettext = new gettext_reader($streamer);
177 $this->_extensioncache['civicrm'] = $this->_phpgettext;
178
179 }
180
181 /**
182 * Return languages available in this instance of CiviCRM.
183 *
184 * @param bool $justEnabled
185 * whether to return all languages or just the enabled ones.
186 *
187 * @return array
188 * Array of code/language name mappings
189 */
190 public static function languages($justEnabled = FALSE) {
191 static $all = NULL;
192 static $enabled = NULL;
193
194 if (!$all) {
195 $all = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
196
197 // get labels
198 $rows = [];
199 $labels = [];
200 CRM_Core_OptionValue::getValues(['name' => 'languages'], $rows);
201 foreach ($rows as $id => $row) {
202 $labels[$row['name']] = $row['label'];
203 }
204
205 // check which ones are available; add them to $all if not there already
206 $codes = [];
207 if (is_dir(CRM_Core_I18n::getResourceDir()) && $dir = opendir(CRM_Core_I18n::getResourceDir())) {
208 while ($filename = readdir($dir)) {
209 if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
210 $codes[] = $filename;
211 if (!isset($all[$filename])) {
212 $all[$filename] = $labels[$filename];
213 }
214 }
215 }
216 closedir($dir);
217 }
218
219 // drop the unavailable languages (except en_US)
220 foreach (array_keys($all) as $code) {
221 if ($code == 'en_US') {
222 continue;
223 }
224 if (!in_array($code, $codes)) {
225 unset($all[$code]);
226 }
227 }
228
229 asort($all);
230 }
231
232 if ($enabled === NULL) {
233 $config = CRM_Core_Config::singleton();
234 $enabled = [];
235 if (isset($config->languageLimit) and $config->languageLimit) {
236 foreach ($all as $code => $name) {
237 if (in_array($code, array_keys($config->languageLimit))) {
238 $enabled[$code] = $name;
239 }
240 }
241 }
242 }
243
244 return $justEnabled ? $enabled : $all;
245 }
246
247 /**
248 * Return the available UI languages
249 * @return array|string
250 * array(string languageCode => string languageName) if !$justCodes
251 */
252 public static function uiLanguages($justCodes = FALSE) {
253 // In multilang we only allow the languages that are configured in db
254 // Otherwise, the languages configured in uiLanguages
255 $settings = Civi::settings();
256 if (CRM_Core_I18n::isMultiLingual()) {
257 $codes = array_keys((array) $settings->get('languageLimit'));
258 }
259 else {
260 $codes = $settings->get('uiLanguages');
261 if (!$codes) {
262 $codes = [$settings->get('lcMessages')];
263 }
264 }
265 return $justCodes ? $codes
266 : CRM_Utils_Array::subset(CRM_Core_I18n::languages(), $codes);
267 }
268
269 /**
270 * Replace arguments in a string with their values. Arguments are represented by % followed by their number.
271 *
272 * @param string $str
273 * source string.
274 *
275 * @return string
276 * modified string
277 */
278 public function strarg($str) {
279 $tr = [];
280 $p = 0;
281 for ($i = 1; $i < func_num_args(); $i++) {
282 $arg = func_get_arg($i);
283 if (is_array($arg)) {
284 foreach ($arg as $aarg) {
285 $tr['%' . ++$p] = $aarg;
286 }
287 }
288 else {
289 $tr['%' . ++$p] = $arg;
290 }
291 }
292 return strtr($str, $tr);
293 }
294
295 /**
296 * Get the directory for l10n resources.
297 *
298 * @return string
299 */
300 public static function getResourceDir() {
301 static $dir = NULL;
302 if ($dir === NULL) {
303 $dir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR;
304 }
305 return $dir;
306 }
307
308 /**
309 * Smarty block function, provides gettext support for smarty.
310 *
311 * The block content is the text that should be translated.
312 *
313 * Any parameter that is sent to the function will be represented as %n in the translation text,
314 * where n is 1 for the first parameter. The following parameters are reserved:
315 * - escape - sets escape mode:
316 * - 'html' for HTML escaping, this is the default.
317 * - 'js' for javascript escaping.
318 * - 'no'/'off'/0 - turns off escaping
319 * - plural - The plural version of the text (2nd parameter of ngettext())
320 * - count - The item count for plural mode (3rd parameter of ngettext())
321 * - context - gettext context of that string (for homonym handling)
322 *
323 * @param string $text
324 * the original string.
325 * @param array $params
326 * The params of the translation (if any).
327 * - domain: string|array a list of translation domains to search (in order)
328 * - context: string
329 *
330 * @return string
331 * the translated string
332 */
333 public function crm_translate($text, $params = []) {
334 if (isset($params['escape'])) {
335 $escape = $params['escape'];
336 unset($params['escape']);
337 }
338
339 // sometimes we need to {ts}-tag a string, but don’t want to
340 // translate it in the template (like civicrm_navigation.tpl),
341 // because we handle the translation in a different way (CRM-6998)
342 // in such cases we return early, only doing SQL/JS escaping
343 if (isset($params['skip']) and $params['skip']) {
344 if (isset($escape) and ($escape == 'sql')) {
345 $text = self::escapeSql($text);
346 }
347 if (isset($escape) and ($escape == 'js')) {
348 $text = addcslashes($text, "'");
349 }
350 return $text;
351 }
352
353 $plural = $count = NULL;
354 if (isset($params['plural'])) {
355 $plural = $params['plural'];
356 unset($params['plural']);
357 if (isset($params['count'])) {
358 $count = $params['count'];
359 }
360 }
361
362 if (isset($params['context'])) {
363 $context = $params['context'];
364 unset($params['context']);
365 }
366 else {
367 $context = NULL;
368 }
369
370 if (isset($params['domain'])) {
371 $domain = $params['domain'];
372 unset($params['domain']);
373 }
374 else {
375 $domain = NULL;
376 }
377
378 $raw = !empty($params['raw']);
379 unset($params['raw']);
380
381 if (!empty($domain)) {
382 // It might be prettier to cast to an array, but this is high-traffic stuff.
383 if (is_array($domain)) {
384 foreach ($domain as $d) {
385 $candidate = $this->crm_translate_raw($text, $d, $count, $plural, $context);
386 if ($candidate != $text) {
387 $text = $candidate;
388 break;
389 }
390 }
391 }
392 else {
393 $text = $this->crm_translate_raw($text, $domain, $count, $plural, $context);
394 }
395 }
396 else {
397 $text = $this->crm_translate_raw($text, NULL, $count, $plural, $context);
398 }
399
400 // replace the numbered %1, %2, etc. params if present
401 if (count($params) && !$raw) {
402 $text = $this->strarg($text, $params);
403 }
404
405 // escape SQL if we were asked for it
406 if (isset($escape) and ($escape == 'sql')) {
407 $text = self::escapeSql($text);
408 }
409
410 // escape for JavaScript (if requested)
411 if (isset($escape) and ($escape == 'js')) {
412 $text = addcslashes($text, "'");
413 }
414
415 return $text;
416 }
417
418 /**
419 * Lookup the raw translation of a string (without any extra escaping or interpolation).
420 *
421 * @param string $text
422 * @param string|null $domain
423 * @param int|null $count
424 * @param string $plural
425 * @param string $context
426 *
427 * @return string
428 */
429 protected function crm_translate_raw($text, $domain, $count, $plural, $context) {
430 // gettext domain for extensions
431 $domain_changed = FALSE;
432 if (!empty($domain) && $this->_phpgettext) {
433 if ($this->setGettextDomain($domain)) {
434 $domain_changed = TRUE;
435 }
436 }
437
438 // do all wildcard translations first
439
440 // FIXME: Is there a constant we can reference instead of hardcoding en_US?
441 $replacementsLocale = $this->locale ? $this->locale : 'en_US';
442 if (!isset(Civi::$statics[__CLASS__]) || !array_key_exists($replacementsLocale, Civi::$statics[__CLASS__])) {
443 if (defined('CIVICRM_DSN') && !CRM_Core_Config::isUpgradeMode()) {
444 Civi::$statics[__CLASS__][$replacementsLocale] = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($replacementsLocale);
445 }
446 else {
447 Civi::$statics[__CLASS__][$replacementsLocale] = [];
448 }
449 }
450 $stringTable = Civi::$statics[__CLASS__][$replacementsLocale];
451
452 $exactMatch = FALSE;
453 if (isset($stringTable['enabled']['exactMatch'])) {
454 foreach ($stringTable['enabled']['exactMatch'] as $search => $replace) {
455 if ($search === $text) {
456 $exactMatch = TRUE;
457 $text = $replace;
458 break;
459 }
460 }
461 }
462
463 if (
464 !$exactMatch &&
465 isset($stringTable['enabled']['wildcardMatch'])
466 ) {
467 $search = array_keys($stringTable['enabled']['wildcardMatch']);
468 $replace = array_values($stringTable['enabled']['wildcardMatch']);
469 $text = str_replace($search, $replace, $text);
470 }
471
472 // dont translate if we've done exactMatch already
473 if (!$exactMatch) {
474 // use plural if required parameters are set
475 if (isset($count) && isset($plural)) {
476
477 if ($this->_phpgettext) {
478 $text = $this->_phpgettext->ngettext($text, $plural, $count);
479 }
480 else {
481 // if the locale's not set, we do ngettext work by hand
482 // if $count == 1 then $text = $text, else $text = $plural
483 if ($count != 1) {
484 $text = $plural;
485 }
486 }
487
488 // expand %count in translated string to $count
489 $text = strtr($text, ['%count' => $count]);
490
491 // if not plural, but the locale's set, translate
492 }
493 elseif ($this->_phpgettext) {
494 if ($context) {
495 $text = $this->_phpgettext->pgettext($context, $text);
496 }
497 else {
498 $text = $this->_phpgettext->translate($text);
499 }
500 }
501 }
502
503 if ($domain_changed) {
504 $this->setGettextDomain('civicrm');
505 }
506
507 return $text;
508 }
509
510 /**
511 * Translate a string to the current locale.
512 *
513 * @param string $string
514 * this string should be translated.
515 *
516 * @return string
517 * the translated string
518 */
519 public function translate($string) {
520 return ($this->_phpgettext) ? $this->_phpgettext->translate($string) : $string;
521 }
522
523 /**
524 * Localize (destructively) array values.
525 *
526 * @param array $array
527 * the array for localization (in place).
528 * @param array $params
529 * an array of additional parameters.
530 */
531 public function localizeArray(
532 &$array,
533 $params = []
534 ) {
535 $tsLocale = CRM_Core_I18n::getLocale();
536
537 if ($tsLocale == 'en_US') {
538 return;
539 }
540
541 foreach ($array as & $value) {
542 if ($value) {
543 $value = ts($value, $params);
544 }
545 }
546 }
547
548 /**
549 * Localize (destructively) array elements with keys of 'title'.
550 *
551 * @param array $array
552 * the array for localization (in place).
553 */
554 public function localizeTitles(&$array) {
555 foreach ($array as $key => $value) {
556 if (is_array($value)) {
557 $this->localizeTitles($value);
558 $array[$key] = $value;
559 }
560 elseif ((string ) $key == 'title') {
561 $array[$key] = ts($value, ['context' => 'menu']);
562 }
563 }
564 }
565
566 /**
567 * Binds a gettext domain, wrapper over bindtextdomain().
568 *
569 * @param $key
570 * Key of the extension (can be 'civicrm', or 'org.example.foo').
571 *
572 * @return Bool
573 * True if the domain was changed for an extension.
574 */
575 public function setGettextDomain($key) {
576 /* No domain changes for en_US */
577 if (!$this->_phpgettext) {
578 return FALSE;
579 }
580
581 // It's only necessary to find/bind once
582 if (!isset($this->_extensioncache[$key])) {
583 try {
584 $mapper = CRM_Extension_System::singleton()->getMapper();
585 $path = $mapper->keyToBasePath($key);
586 $info = $mapper->keyToInfo($key);
587 $domain = $info->file;
588
589 if ($this->_nativegettext) {
590 bindtextdomain($domain, $path . DIRECTORY_SEPARATOR . 'l10n');
591 bind_textdomain_codeset($domain, 'UTF-8');
592 $this->_extensioncache[$key] = $domain;
593 }
594 else {
595 // phpgettext
596 $mo_file = $path . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR . $this->locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . $domain . '.mo';
597 $streamer = new FileReader($mo_file);
598 $this->_extensioncache[$key] = new gettext_reader($streamer);
599 }
600 }
601 catch (CRM_Extension_Exception $e) {
602 // Intentionally not translating this string to avoid possible infinite loops
603 // Only developers should see this string, if they made a mistake in their ts() usage.
604 CRM_Core_Session::setStatus('Unknown extension key in a translation string: ' . $key, '', 'error');
605 $this->_extensioncache[$key] = FALSE;
606 }
607 }
608
609 if (isset($this->_extensioncache[$key]) && $this->_extensioncache[$key]) {
610 if ($this->_nativegettext) {
611 textdomain($this->_extensioncache[$key]);
612 }
613 else {
614 $this->_phpgettext = $this->_extensioncache[$key];
615 }
616
617 return TRUE;
618 }
619
620 return FALSE;
621 }
622
623 /**
624 * Is the CiviCRM in multilingual mode.
625 *
626 * @return Bool
627 * True if CiviCRM is in multilingual mode.
628 */
629 public static function isMultilingual() {
630 $domain = new CRM_Core_DAO_Domain();
631 $domain->find(TRUE);
632 return (bool) $domain->locales;
633 }
634
635 /**
636 * Is the language written "right-to-left"?
637 *
638 * @param $language
639 * Language (for example 'en_US', or 'fr_CA').
640 *
641 * @return Bool
642 * True if it is an RTL language.
643 */
644 public static function isLanguageRTL($language) {
645 $rtl = CRM_Core_I18n_PseudoConstant::getRTLlanguages();
646 $short = CRM_Core_I18n_PseudoConstant::shortForLong($language);
647
648 return (in_array($short, $rtl));
649 }
650
651 /**
652 * Change the processing language without changing the current user language
653 *
654 * @param $locale
655 * Locale (for example 'en_US', or 'fr_CA').
656 * True if the domain was changed for an extension.
657 */
658 public function setLocale($locale) {
659
660 // Change the language of the CMS as well, for URLs.
661 CRM_Utils_System::setUFLocale($locale);
662
663 // change the gettext ressources
664 if ($this->_nativegettext) {
665 $this->setNativeGettextLocale($locale);
666 }
667 else {
668 // phpgettext
669 $this->setPhpGettextLocale($locale);
670 }
671
672 // For sql queries, if running in DB multi-lingual mode.
673 global $dbLocale;
674
675 if ($dbLocale) {
676 $dbLocale = "_{$locale}";
677 }
678
679 // For self::getLocale()
680 global $tsLocale;
681 $tsLocale = $locale;
682 }
683
684 /**
685 * Static instance provider - return the instance for the current locale.
686 *
687 * @return CRM_Core_I18n
688 */
689 public static function &singleton() {
690 if (!isset(Civi::$statics[__CLASS__]['singleton'])) {
691 Civi::$statics[__CLASS__]['singleton'] = [];
692 }
693 $tsLocale = CRM_Core_I18n::getLocale();
694 if (!isset(Civi::$statics[__CLASS__]['singleton'][$tsLocale])) {
695 Civi::$statics[__CLASS__]['singleton'][$tsLocale] = new CRM_Core_I18n($tsLocale);
696 }
697
698 return Civi::$statics[__CLASS__]['singleton'][$tsLocale];
699 }
700
701 /**
702 * Set the LC_TIME locale if it's not set already (for a given language choice).
703 *
704 * @return string
705 * the final LC_TIME that got set
706 */
707 public static function setLcTime() {
708 static $locales = [];
709
710 $tsLocale = CRM_Core_I18n::getLocale();
711 if (!isset($locales[$tsLocale])) {
712 // with the config being set to pl_PL: try pl_PL.UTF-8,
713 // then pl_PL, if neither present fall back to C
714 $locales[$tsLocale] = setlocale(LC_TIME, $tsLocale . '.UTF-8', $tsLocale, 'C');
715 }
716
717 return $locales[$tsLocale];
718 }
719
720 /**
721 * Get the default language for contacts where no language is provided.
722 *
723 * Note that NULL is a valid option so be careful with checking for empty etc.
724 *
725 * NULL would mean 'we don't know & we don't want to hazard a guess'.
726 *
727 * @return string
728 */
729 public static function getContactDefaultLanguage() {
730 $language = Civi::settings()->get('contact_default_language');
731 if ($language == 'undefined') {
732 return NULL;
733 }
734 if (empty($language) || $language === '*default*') {
735 $language = civicrm_api3('setting', 'getvalue', [
736 'name' => 'lcMessages',
737 'group' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
738 ]);
739 }
740 elseif ($language == 'current_site_language') {
741 return CRM_Core_I18n::getLocale();
742 }
743
744 return $language;
745 }
746
747 /**
748 * Get the current locale
749 *
750 * @return string
751 */
752 public static function getLocale() {
753 global $tsLocale;
754 return $tsLocale ? $tsLocale : 'en_US';
755 }
756
757 }
758
759 /**
760 * Short-named function for string translation, defined in global scope so it's available everywhere.
761 *
762 * @param string $text
763 * String string for translating.
764 * @param array $params
765 * Array an array of additional parameters.
766 *
767 * @return string
768 * the translated string
769 */
770 function ts($text, $params = []) {
771 static $areSettingsAvailable = FALSE;
772 static $lastLocale = NULL;
773 static $i18n = NULL;
774 static $function = NULL;
775
776 if ($text == '') {
777 return '';
778 }
779
780 // When the settings become available, lookup customTranslateFunction.
781 if (!$areSettingsAvailable) {
782 $areSettingsAvailable = (bool) \Civi\Core\Container::getBootService('settings_manager');
783 if ($areSettingsAvailable) {
784 $config = CRM_Core_Config::singleton();
785 if (isset($config->customTranslateFunction) and function_exists($config->customTranslateFunction)) {
786 $function = $config->customTranslateFunction;
787 }
788 }
789 }
790
791 $activeLocale = CRM_Core_I18n::getLocale();
792 if (!$i18n or $lastLocale != $activeLocale) {
793 $i18n = CRM_Core_I18n::singleton();
794 $lastLocale = $activeLocale;
795 }
796
797 if ($function) {
798 return $function($text, $params);
799 }
800 else {
801 return $i18n->crm_translate($text, $params);
802 }
803 }