diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 19e0552..5257289 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1468,27 +1468,6 @@ function bootstrap_hooks() { */ function t($string, array $args = array(), array $options = array()) { static $custom_strings; - $locale_exists = &drupal_static(__FUNCTION__); - - // Check whether locale() is available and operational. - if (!isset($locale_exits)) { - // The availability of locale() requires more explanation: - // - Whether the module system has been loaded. - // In early bootstrap, in the installer, update.php, and also in early - // error/exception conditions, the module system might not be loaded yet. - // - Whether Locale module is enabled. - // The mere existence of locale() does not imply that Locale module is - // actually enabled and its database tables are installed. Since PHP code - // cannot be unloaded, this is typically the case in the environment that - // is executing a test. - // - Whether Locale module actually has been loaded and locale() exists. - // The Locale module may be enabled, but the actual .module might not be - // loaded. This is typically the case in update.php, which needs to - // populate the full module list to invoke hook_requirements(), but must - // not load any actual modules and APIs, since they are not guaranteed to - // be operational. - $locale_exists = function_exists('locale') && function_exists('module_exists') && module_exists('locale'); - } // Merge in default. if (empty($options['langcode'])) { @@ -1510,7 +1489,7 @@ function t($string, array $args = array(), array $options = array()) { $string = $custom_strings[$options['langcode']][$options['context']][$string]; } // Translate with locale module if enabled. - elseif ($options['langcode'] != LANGUAGE_SYSTEM && ($options['langcode'] != 'en' || variable_get('locale_translate_english', FALSE)) && $locale_exists) { + elseif ($options['langcode'] != LANGUAGE_SYSTEM && ($options['langcode'] != 'en' || variable_get('locale_translate_english', FALSE)) && function_exists('locale')) { $string = locale($string, $options['context'], $options['langcode']); } if (empty($args)) { diff --git a/core/includes/cache.inc b/core/includes/cache.inc index 72339b0..341d77f 100644 --- a/core/includes/cache.inc +++ b/core/includes/cache.inc @@ -26,7 +26,12 @@ * @see Drupal\Core\Cache\CacheBackendInterface */ function cache($bin = 'cache') { - $cache_objects = &drupal_static(__FUNCTION__, array()); + // Use the advanced drupal_static() pattern, since this is called very often. + static $drupal_static_fast; + if (!isset($drupal_static_fast)) { + $drupal_static_fast['cache'] = &drupal_static(__FUNCTION__, array()); + } + $cache_objects = &$drupal_static_fast['cache']; // Temporary backwards compatibiltiy layer, allow old style prefixed cache // bin names to be passed as arguments. diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 39febca..d535a0f 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -254,10 +254,23 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) { // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { - $drupal_static_fast['locale'] = &drupal_static(__FUNCTION__); + $drupal_static_fast['cache'] = &drupal_static(__FUNCTION__ . ':cache'); + $drupal_static_fast['exists'] = &drupal_static(__FUNCTION__ . ':exists'); } - $locale_t = &$drupal_static_fast['locale']; + $locale_t = &$drupal_static_fast['cache']; + $locale_exists = &$drupal_static_fast['exists']; + // Check whether Locale module is actually installed and operational. + // The mere existence of locale() does not imply that Locale module is + // actually enabled and its database tables are installed. Since PHP code + // cannot be unloaded, this is typically the case in the environment that + // is executing a test. + if (!isset($locale_exits)) { + $locale_exists = function_exists('module_exists') && module_exists('locale'); + } + if (!$locale_exists) { + return $string; + } if (!isset($string)) { // Return all cached strings if no string was specified