From 852de6cf0592b93616f4f03e1bdb33896979937d Mon Sep 17 00:00:00 2001 From: "B. Endres" Date: Sun, 6 Oct 2019 23:46:35 +0200 Subject: [PATCH] implemented @totten's approach to fix custom ts functions in extensions --- CRM/Core/I18n.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index f6ef3f4de1..fcb0ed6552 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -768,7 +768,7 @@ class CRM_Core_I18n { * the translated string */ function ts($text, $params = []) { - static $areSettingsAvailable = FALSE; + static $bootstrapReady = FALSE; static $lastLocale = NULL; static $i18n = NULL; static $function = NULL; @@ -778,14 +778,19 @@ function ts($text, $params = []) { } // 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 + return $text; + } } $activeLocale = CRM_Core_I18n::getLocale(); -- 2.25.1