- if ($requestLocale) {
- $ufm = new CRM_Core_DAO_UFMatch();
- $ufm->contact_id = $session->get('userID');
- if ($ufm->find(TRUE)) {
- $ufm->language = $chosenLocale;
- $ufm->save();
+ /*
+ * Maybe inherit the language from the CMS.
+ *
+ * If the language is specified via "lcMessages" we skip this, since the
+ * intention of the URL query var is to override all other sources.
+ */
+ if ($settings->get('inheritLocale')) {
+
+ /*
+ * FIXME: On multi-language installs, CRM_Utils_System::getUFLocale() in
+ * many cases returns nothing if $dbLocale is not set, so set it to the
+ * default - even if it's overridden later.
+ */
+ $dbLocale = $multiLang && $defaultLocale ? "_{$defaultLocale}" : '';
+
+ // Retrieve locale as reported by CMS.
+ $cmsLocale = CRM_Utils_System::getUFLocale();
+ if (in_array($cmsLocale, $permittedLanguages)) {
+ $chosenLocale = $cmsLocale;