Commit 6a35be0c authored by bgm's avatar bgm Committed by GitHub

Merge pull request #12139 from JMAConsulting/dev-drupal-17

(dev/drupal/17) Add Drupal8 support for getUFLocale()
parents 917f6f2d ea9245cc
......@@ -650,4 +650,18 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase {
return $this->url($current_path);
}
/**
* Function to return current language of Drupal8
*
* @return string
*/
public function getCurrentLanguage() {
// Drupal might not be bootstrapped if being called by the REST API.
if (!class_exists('Drupal')) {
return NULL;
}
return \Drupal::languageManager()->getCurrentLanguage()->getId();
}
}
......@@ -450,25 +450,25 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
// 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;
$language = $this->getCurrentLanguage();
if (empty($language)) {
return NULL;
}
if ($language->language == 'zh-hans') {
if ($language == 'zh-hans') {
return 'zh_CN';
}
if ($language->language == 'zh-hant') {
if ($language == 'zh-hant') {
return 'zh_TW';
}
if (preg_match('/^.._..$/', $language->language)) {
return $language->language;
if (preg_match('/^.._..$/', $language)) {
return $language;
}
return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2));
return CRM_Core_I18n_PseudoConstant::longForShort(substr($language, 0, 2));
}
/**
......@@ -664,4 +664,14 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
}
}
/**
* Function to return current language of Drupal
*
* @return string
*/
public function getCurrentLanguage() {
global $language;
return (!empty($language->language)) ? $language->language : $language;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment