From: Donald A. Lobo Date: Mon, 20 May 2013 16:04:26 +0000 (-0700) Subject: handle global variable $language not being set, restructure code a bit X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1c9f455cb36bc162ce74c1a56b69be75c25d0393;p=civicrm-core.git handle global variable $language not being set, restructure code a bit --- diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index 9f746990e2..c1652527aa 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -696,20 +696,26 @@ AND u.status = 1 function getUFLocale() { // return CiviCRM’s xx_YY locale that either matches Drupal’s Chinese locale // (for CRM-6281), Drupal’s xx_YY or is retrieved based on Drupal’s xx + // sometimes for CLI based on order called, this might not be set and/or empty global $language; - switch (TRUE) { - case $language->language == 'zh-hans': - return 'zh_CN'; - case $language->language == 'zh-hant': - return 'zh_TW'; + if (empty($language)) { + return NULL; + } - case preg_match('/^.._..$/', $language->language): - return $language->language; + if ($language->language == 'zh-hans') { + return 'zh_CN'; + } - default: - return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2)); + if ($language->language == 'zh-hant') { + return 'zh_TW'; } + + if (preg_match('/^.._..$/', $language->language)) { + return $language->language; + } + + return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2)); } function getVersion() {