Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom ts functions in extensions; defer custom ts calls until booted #15411

Merged
merged 4 commits into from
Oct 7, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
implemented @totten's approach to fix custom ts functions in extensions
  • Loading branch information
bjendres committed Oct 6, 2019
commit 852de6cf0592b93616f4f03e1bdb33896979937d
13 changes: 9 additions & 4 deletions CRM/Core/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ public static function getLocale() {
* the translated string
*/
function ts($text, $params = []) {
static $areSettingsAvailable = FALSE;
static $bootstrapReady = FALSE;
static $lastLocale = NULL;
static $i18n = NULL;
static $function = NULL;
Expand All @@ -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();
Expand Down