CRM-16355 - bgm addon to change CMS locale
[civicrm-core.git] / CRM / Utils / System / DrupalBase.php
index aeab9544e228dcb4854833d1186afb85c91f8b17..56cf330f94d72982dea8d1b9bb198b4e76438ed5 100644 (file)
@@ -425,6 +425,29 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
     return CRM_Core_I18n_PseudoConstant::longForShort(substr($language->language, 0, 2));
   }
 
+  /**
+   * @inheritDoc
+   */
+  public function setUFLocale($civicrm_language) {
+    global $language;
+
+    $langcode = substr($civicrm_language, 0, 2);
+    $languages = language_list();
+
+    if (isset($languages[$langcode])) {
+      $language = $languages[$langcode];
+
+      // Config must be re-initialized to reset the base URL
+      // otherwise links will have the wrong language prefix/domain.
+      $config = CRM_Core_Config::singleton();
+      $config->free();
+
+      return TRUE;
+    }
+
+    return FALSE;
+  }
+
   /**
    * Perform any post login activities required by the UF -
    * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,