From 98466ff94ea881af1c0b588313a8e84035359c06 Mon Sep 17 00:00:00 2001 From: sunil Date: Fri, 8 Apr 2016 11:45:17 +0530 Subject: [PATCH] CRM-18362, additional cleanup --- CRM/Contribute/BAO/ContributionPage.php | 2 +- CRM/Core/BAO/ConfigSetting.php | 3 +-- CRM/Core/I18n.php | 20 ++++++++++++++------ CRM/Core/I18n/Form.php | 2 +- CRM/Core/PseudoConstant.php | 6 +++--- CRM/Core/Resources.php | 4 ++-- CRM/Core/Smarty.php | 4 ++-- Civi/API/Subscriber/I18nSubscriber.php | 3 +-- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index 990eefb846..beae633c7c 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -847,7 +847,7 @@ LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm * @return array|string */ public static function formatModuleData($params, $setDefault = FALSE, $module) { - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); $config = CRM_Core_Config::singleton(); $json = $jsonDecode = NULL; $domain = new CRM_Core_DAO_Domain(); diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index e2a708c3dc..39506c65b7 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -212,8 +212,7 @@ class CRM_Core_BAO_ConfigSetting { $dbLocale = $multiLang ? "_{$chosenLocale}" : ''; // FIXME: an ugly hack to fix CRM-4041 - global $tsLocale; - $tsLocale = $chosenLocale; + CRM_Core_I18n::setLocale($chosenLocale); // FIXME: as bad aplace as any to fix CRM-5428 // (to be moved to a sane location along with the above) diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index 94d8ed6272..5396e9e19c 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -441,7 +441,7 @@ class CRM_Core_I18n { &$array, $params = array() ) { - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if ($tsLocale == 'en_US') { return; @@ -615,7 +615,7 @@ class CRM_Core_I18n { public static function &singleton() { static $singleton = array(); - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if (!isset($singleton[$tsLocale])) { $singleton[$tsLocale] = new CRM_Core_I18n($tsLocale); } @@ -632,7 +632,7 @@ class CRM_Core_I18n { public static function setLcTime() { static $locales = array(); - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if (!isset($locales[$tsLocale])) { // with the config being set to pl_PL: try pl_PL.UTF-8, // then pl_PL, if neither present fall back to C @@ -663,8 +663,7 @@ class CRM_Core_I18n { )); } elseif ($language == 'current_site_language') { - global $tsLocale; - return $tsLocale; + return CRM_Core_I18n::getLocale(); } return $language; @@ -680,6 +679,15 @@ class CRM_Core_I18n { return $tsLocale; } + /** + * Set the current locale + * @param $locale + */ + public static function setLocale($locale) { + global $tsLocale; + $tsLocale = $locale; + } + } /** @@ -707,7 +715,7 @@ function ts($text, $params = array()) { $config = CRM_Core_Config::singleton(); } - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if (!$i18n or $locale != $tsLocale) { $i18n = CRM_Core_I18n::singleton(); $locale = $tsLocale; diff --git a/CRM/Core/I18n/Form.php b/CRM/Core/I18n/Form.php index 6cbb7859ed..f2fa0a5838 100644 --- a/CRM/Core/I18n/Form.php +++ b/CRM/Core/I18n/Form.php @@ -35,7 +35,7 @@ class CRM_Core_I18n_Form extends CRM_Core_Form { public function buildQuickForm() { $config = CRM_Core_Config::singleton(); - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); $this->_locales = array_keys($config->languageLimit); // get the part of the database we want to edit and validate it diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index be78d7111f..dc737bb721 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -706,7 +706,7 @@ class CRM_Core_PseudoConstant { self::populate(self::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause); // localise the province names if in an non-en_US locale - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if ($tsLocale != '' and $tsLocale != 'en_US') { $i18n = CRM_Core_I18n::singleton(); $i18n->localizeArray(self::$stateProvince, array( @@ -837,7 +837,7 @@ WHERE id = %1"; } // localise the country names if in an non-en_US locale - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if ($tsLocale != '' and $tsLocale != 'en_US') { $i18n = CRM_Core_I18n::singleton(); $i18n->localizeArray(self::$country, array( @@ -1565,7 +1565,7 @@ ORDER BY name"; // localise the stateProvince names if in an non-en_US locale $config = CRM_Core_Config::singleton(); - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if ($tsLocale != '' and $tsLocale != 'en_US') { $i18n = CRM_Core_I18n::singleton(); $i18n->localizeArray($result, array( diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 83cb73686e..67ec542aa7 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -603,7 +603,7 @@ class CRM_Core_Resources { } } - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); // Dynamic localization script $this->addScriptUrl(CRM_Utils_System::url('civicrm/ajax/l10n-js/' . $tsLocale, array('r' => $this->getCacheCode())), $jsWeight++, $region); @@ -753,7 +753,7 @@ class CRM_Core_Resources { $items[] = "js/crm.optionEdit.js"; } - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); // Add localized jQuery UI files if ($tsLocale && $tsLocale != 'en_US') { // Search for i18n file in order of specificity (try fr-CA, then fr) diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index 40b2a91e85..5a3cb1cfa8 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -146,7 +146,7 @@ class CRM_Core_Smarty extends Smarty { $this->assign_by_ref('config', $config); $this->assign_by_ref('session', $session); - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); $this->assign('tsLocale', $tsLocale); // CRM-7163 hack: we don’t display langSwitch on upgrades anyway @@ -318,7 +318,7 @@ class CRM_Core_Smarty extends Smarty { } private function getLocale() { - global $tsLocale; + $tsLocale = CRM_Core_I18n::getLocale(); if (!empty($tsLocale)) { return $tsLocale; } diff --git a/Civi/API/Subscriber/I18nSubscriber.php b/Civi/API/Subscriber/I18nSubscriber.php index 11b72e9cec..b87f8fbed7 100644 --- a/Civi/API/Subscriber/I18nSubscriber.php +++ b/Civi/API/Subscriber/I18nSubscriber.php @@ -102,8 +102,7 @@ class I18nSubscriber implements EventSubscriberInterface { $dbLocale = $multiLang && $lcMessages ? "_{$lcMessages}" : ''; // FIXME: an ugly hack to fix CRM-4041 - global $tsLocale; - $tsLocale = $lcMessages; + \CRM_Core_I18n::setLocale($lcMessages); } } } -- 2.25.1