Skip to content

Commit

Permalink
refs #41568, before remove require_once, move global callable functio…
Browse files Browse the repository at this point in the history
…ns to new file
  • Loading branch information
jimyhuang committed Sep 13, 2024
1 parent 60a3e4f commit bb49545
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CRM/Core/ClassLoader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

require_once __DIR__.'/../../functions.php';
class CRM_Core_ClassLoader {
/**
* We only need one instance of this object. So we use the singleton
Expand Down
42 changes: 0 additions & 42 deletions CRM/Core/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,45 +426,3 @@ public static function isMultilingual() {
}
}

/**
* Short-named function for string translation, defined in global scope so it's available everywhere.
*
* @param $text string string for translating
* @param $params array an array of additional parameters
*
* @return string the translated string
*/
function ts($text, $params = array()) {
static $function;
static $locale;
global $tsLocale;

if (empty($tsLocale)) {
return $text;
}

if (empty($text)) {
return '';
}

$i18n = CRM_Core_I18n::singleton();
if($locale != $tsLocale){
$locale = $tsLocale;
if (!empty($i18n->_customTranslateFunction) && $function === NULL) {
if (function_exists($i18n->_customTranslateFunction)) {
$function = $i18n->_customTranslateFunction;
}
else {
$function = FALSE;
}
}
}

if ($function) {
return $function($text, $params);
}
else {
return $i18n->crm_translate($text, $params);
}
}

43 changes: 43 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Short-named function for string translation, defined in global scope so it's available everywhere.
*
* @param $text string string for translating
* @param $params array an array of additional parameters
*
* @return string the translated string
*/
function ts($text, $params = array()) {
static $function;
static $locale;
global $tsLocale;

if (empty($tsLocale)) {
return $text;
}

if (empty($text)) {
return '';
}

$i18n = CRM_Core_I18n::singleton();
if($locale != $tsLocale){
$locale = $tsLocale;
if (!empty($i18n->_customTranslateFunction) && $function === NULL) {
if (function_exists($i18n->_customTranslateFunction)) {
$function = $i18n->_customTranslateFunction;
}
else {
$function = FALSE;
}
}
}

if ($function) {
return $function($text, $params);
}
else {
return $i18n->crm_translate($text, $params);
}
}

0 comments on commit bb49545

Please sign in to comment.