diff --git a/CRM/Core/BAO/Translation.php b/CRM/Core/BAO/Translation.php index 61c9007db5fc..099c0bef876f 100644 --- a/CRM/Core/BAO/Translation.php +++ b/CRM/Core/BAO/Translation.php @@ -178,7 +178,7 @@ public static function hook_civicrm_apiWrappers(&$wrappers, $apiRequest): void { } $communicationLanguage = \Civi\Core\Locale::detect()->nominal; - if ($communicationLanguage === Civi::settings()->get('lcMessages')) { + if (!$communicationLanguage || !self::isTranslate($communicationLanguage)) { return; } @@ -205,6 +205,34 @@ public static function hook_civicrm_apiWrappers(&$wrappers, $apiRequest): void { } } + /** + * Should the translation process be followed. + * + * It can be short-circuited if there we are in the site default language and + * it is not translated. + * + * @param string $communicationLanguage + * + * @return bool + */ + protected static function isTranslate(string $communicationLanguage): bool { + if ($communicationLanguage !== Civi::settings()->get('lcMessages')) { + return TRUE; + } + if (!isset(\Civi::$statics[__CLASS__]['translate_main'][$communicationLanguage])) { + // The code had an assumption that you would not translate the primary language. + // However, the UI is such that the features (approval flow) so it makes sense + // to translation the default site language as well. If we can see sites are + // doing this then let's treat the main locale like any other locale + \Civi::$statics[__CLASS__]['translate_main'] = (bool) CRM_Core_DAO::singleValueQuery( + 'SELECT COUNT(*) FROM civicrm_translation WHERE language = %1 LIMIT 1', [ + 1 => [$communicationLanguage, 'String'], + ] + ); + } + return \Civi::$statics[__CLASS__]['translate_main']; + } + /** * @param \Civi\Api4\Generic\AbstractAction $apiRequest * @return array translated fields.