CRM-19372 allow payment processors to define an array of accepted credit card types
[civicrm-core.git] / CRM / Core / I18n.php
index 67960dff0cc0e848180d54298ce9a833d8e5447d..93ceaa510f79ca6393446a379c743f20a9ec5487 100644 (file)
@@ -348,15 +348,17 @@ class CRM_Core_I18n {
 
     // do all wildcard translations first
 
-    if (!isset(Civi::$statics[__CLASS__]) || !array_key_exists($this->locale, Civi::$statics[__CLASS__])) {
+    // FIXME: Is there a constant we can reference instead of hardcoding en_US?
+    $replacementsLocale = $this->locale ? $this->locale : 'en_US';
+    if (!isset(Civi::$statics[__CLASS__]) || !array_key_exists($replacementsLocale, Civi::$statics[__CLASS__])) {
       if (defined('CIVICRM_DSN') && !CRM_Core_Config::isUpgradeMode()) {
-        Civi::$statics[__CLASS__][$this->locale] = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($this->locale);
+        Civi::$statics[__CLASS__][$replacementsLocale] = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($replacementsLocale);
       }
       else {
-        Civi::$statics[__CLASS__][$this->locale] = array();
+        Civi::$statics[__CLASS__][$replacementsLocale] = array();
       }
     }
-    $stringTable = Civi::$statics[__CLASS__][$this->locale];
+    $stringTable = Civi::$statics[__CLASS__][$replacementsLocale];
 
     $exactMatch = FALSE;
     if (isset($stringTable['enabled']['exactMatch'])) {
@@ -441,7 +443,7 @@ class CRM_Core_I18n {
     &$array,
     $params = array()
   ) {
-    global $tsLocale;
+    $tsLocale = CRM_Core_I18n::getLocale();
 
     if ($tsLocale == 'en_US') {
       return;
@@ -615,7 +617,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 +634,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,13 +665,22 @@ class CRM_Core_I18n {
       ));
     }
     elseif ($language == 'current_site_language') {
-      global $tsLocale;
-      return $tsLocale;
+      return CRM_Core_I18n::getLocale();
     }
 
     return $language;
   }
 
+  /**
+   * Get the current locale
+   *
+   * @return string
+   */
+  public static function getLocale() {
+    global $tsLocale;
+    return $tsLocale;
+  }
+
 }
 
 /**
@@ -697,7 +708,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;