From 6b4aa3080f37c589b7d7cb30fecae450f1ac3abc Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sun, 10 Jan 2010 19:06:47 +0000 Subject: #480424 by JamesAn: Update locale module to use drupal_static(). --- modules/locale/locale.module | 25 +++++++++++++------------ modules/locale/locale.test | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'modules') diff --git a/modules/locale/locale.module b/modules/locale/locale.module index dff3570aa..67cb9491a 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -575,17 +575,10 @@ function locale_language_negotiation_info() { * The context of this string. * @param $langcode * Language code to use for the lookup. - * @param $reset - * Set to TRUE to reset the in-memory cache. */ -function locale($string = NULL, $context = NULL, $langcode = NULL, $reset = FALSE) { +function locale($string = NULL, $context = NULL, $langcode = NULL) { global $language; - static $locale_t; - - if ($reset) { - // Reset in-memory cache. - $locale_t = NULL; - } + $locale_t = &drupal_static(__FUNCTION__); if (!isset($string)) { // Return all cached strings if no string was specified @@ -665,6 +658,13 @@ function locale($string = NULL, $context = NULL, $langcode = NULL, $reset = FALS return ($locale_t[$langcode][$context][$string] === TRUE ? $string : $locale_t[$langcode][$context][$string]); } +/** + * Reset static variables used by locale(). + */ +function locale_reset() { + drupal_static_reset('locale'); +} + /** * Returns plural form index for a specific number. * @@ -678,12 +678,13 @@ function locale($string = NULL, $context = NULL, $langcode = NULL, $reset = FALS */ function locale_get_plural($count, $langcode = NULL) { global $language; - static $locale_formula, $plurals = array(); + $locale_formula = &drupal_static(__FUNCTION__, array()); + $plurals = &drupal_static(__FUNCTION__ . ':plurals', array()); $langcode = $langcode ? $langcode : $language->language; if (!isset($plurals[$langcode][$count])) { - if (!isset($locale_formula)) { + if (empty($locale_formula)) { $language_list = language_list(); $locale_formula[$langcode] = $language_list[$langcode]->formula; } @@ -705,7 +706,7 @@ function locale_get_plural($count, $langcode = NULL) { * Returns a language name */ function locale_language_name($lang) { - static $list = NULL; + $list = &drupal_static(__FUNCTION__); if (!isset($list)) { $list = locale_language_list(); } diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 061bf04f3..2e52dc060 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -201,7 +201,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase { // Add string. t($name, array(), array('langcode' => $langcode)); // Reset locale cache. - locale(NULL, NULL, NULL, TRUE); + locale_reset(); $this->assertText($langcode, t('Language code found.')); $this->assertText($name, t('Name found.')); $this->assertText($native, t('Native found.')); @@ -456,7 +456,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase { // Add string. t($name, array(), array('langcode' => $langcode)); // Reset locale cache. - locale(NULL, NULL, NULL, TRUE); + locale_reset(); $this->drupalLogout(); // Search for the name. -- cgit v1.2.3