- // support multi-lingual requests
- if ($language = \CRM_Utils_Array::value('option.language', $apiRequest['params'])) {
- $this->setLocale($language);
+ $params = $apiRequest['params'];
+ if ($apiRequest['version'] < 4) {
+ $language = !empty($params['options']['language']) ? $params['options']['language'] : \CRM_Utils_Array::value('option.language', $params);
+ }
+ else {
+ $language = \CRM_Utils_Array::value('language', $params);
+ }
+ if ($language) {
+ $this->setLocale($language, $apiRequest['id']);
+ }
+ }
+
+ /**
+ * Reset language to the default.
+ *
+ * @param \Civi\API\Event\Event $event
+ *
+ * @throws \API_Exception
+ */
+ public function onApiRespond(\Civi\API\Event\Event $event) {
+ $apiRequest = $event->getApiRequest();
+
+ if (!empty($this->originalLang[$apiRequest['id']])) {
+ global $tsLocale;
+ global $dbLocale;
+ $tsLocale = $this->originalLang[$apiRequest['id']]['tsLocale'];
+ $dbLocale = $this->originalLang[$apiRequest['id']]['dbLocale'];