Skip to content

Commit

Permalink
[PATCH] Merge pull request civicrm#15411 from systopia/dev_l10nx
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 authored and bjendres committed Oct 9, 2019
1 parent 089e2ac commit 0fe5719
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions CRM/Core/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public static function getResourceDir() {
* The params of the translation (if any).
* - domain: string|array a list of translation domains to search (in order)
* - context: string
* - skip_translation: flag (do only escape/replacement, skip the actual translation)
*
* @return string
* the translated string
Expand Down Expand Up @@ -353,24 +354,26 @@ public function crm_translate($text, $params = array()) {
$raw = !empty($params['raw']);
unset($params['raw']);

if (!empty($domain)) {
// It might be prettier to cast to an array, but this is high-traffic stuff.
if (is_array($domain)) {
foreach ($domain as $d) {
$candidate = $this->crm_translate_raw($text, $d, $count, $plural, $context);
if ($candidate != $text) {
$text = $candidate;
break;
if (!isset($params['skip_translation'])) {
if (!empty($domain)) {
// It might be prettier to cast to an array, but this is high-traffic stuff.
if (is_array($domain)) {
foreach ($domain as $d) {
$candidate = $this->crm_translate_raw($text, $d, $count, $plural, $context);
if ($candidate != $text) {
$text = $candidate;
break;
}
}
}
else {
$text = $this->crm_translate_raw($text, $domain, $count, $plural, $context);
}
}
else {
$text = $this->crm_translate_raw($text, $domain, $count, $plural, $context);
$text = $this->crm_translate_raw($text, NULL, $count, $plural, $context);
}
}
else {
$text = $this->crm_translate_raw($text, NULL, $count, $plural, $context);
}

// replace the numbered %1, %2, etc. params if present
if (count($params) && !$raw) {
Expand Down Expand Up @@ -736,8 +739,8 @@ public static function getLocale() {
* @return string
* the translated string
*/
function ts($text, $params = array()) {
static $areSettingsAvailable = FALSE;
function ts($text, $params = []) {
static $bootstrapReady = FALSE;
static $lastLocale = NULL;
static $i18n = NULL;
static $function = NULL;
Expand All @@ -747,14 +750,19 @@ function ts($text, $params = array()) {
}

// When the settings become available, lookup customTranslateFunction.
if (!$areSettingsAvailable) {
$areSettingsAvailable = (bool) \Civi\Core\Container::getBootService('settings_manager');
if ($areSettingsAvailable) {
if (!$bootstrapReady) {
$bootstrapReady = (bool) \Civi\Core\Container::isContainerBooted();
if ($bootstrapReady) {
// just got ready: determine whether there is a working custom translation function
$config = CRM_Core_Config::singleton();
if (isset($config->customTranslateFunction) and function_exists($config->customTranslateFunction)) {
$function = $config->customTranslateFunction;
}
}
else {
// don't _translate_ anything until bootstrap has progressed enough
$params['skip_translation'] = 1;
}
}

$activeLocale = CRM_Core_I18n::getLocale();
Expand Down

0 comments on commit 0fe5719

Please sign in to comment.