+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
*/
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'])) {
&$array,
$params = array()
) {
- global $tsLocale;
+ $tsLocale = CRM_Core_I18n::getLocale();
if ($tsLocale == 'en_US') {
return;
return (bool) $domain->locales;
}
+ /**
+ * Is the language written "right-to-left"?
+ *
+ * @param $language
+ * Language (for example 'en_US', or 'fr_CA').
+ *
+ * @return Bool
+ * True if it is an RTL language.
+ */
+ public static function isLanguageRTL($language) {
+ $rtl = CRM_Core_I18n_PseudoConstant::getRTLlanguages();
+ $short = CRM_Core_I18n_PseudoConstant::shortForLong($language);
+
+ return (in_array($short, $rtl));
+ }
/**
* Change the processing language without changing the current user language
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);
}
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
));
}
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;
+ }
+
}
/**
$config = CRM_Core_Config::singleton();
}
- global $tsLocale;
+ $tsLocale = CRM_Core_I18n::getLocale();
if (!$i18n or $locale != $tsLocale) {
$i18n = CRM_Core_I18n::singleton();
$locale = $tsLocale;