From 1c9f455cb36bc162ce74c1a56b69be75c25d0393 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Mon, 20 May 2013 09:04:26 -0700 Subject: [PATCH] handle global variable $language not being set, restructure code a bit --- CRM/Utils/System/Drupal.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) 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() { -- 2.25.1