Setup UI - Fix translation of post-install messages
authorTim Otten <totten@civicrm.org>
Tue, 7 Jul 2020 23:07:49 +0000 (16:07 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 7 Jul 2020 23:12:09 +0000 (16:12 -0700)
Here's what happens:

- The "Setup" subsystem does its internal/partial bootstrap; it sets `$tsLocale` and uses `CRM_Core_I18n`. Hooray.
- The "Setup" initializes the database/settings and then does a full bootstrap. The full bootstrap step calls `applyLocale()`, which replaces the active `$tsLocale`... with the *unconfigured default*. Ooops.
- This step runs next - and it updates the DB setting. But we've already trampled `$tsLocale`. Calling `applyLocale()` a second time means we use the preferred `$tsLocale` again. Hooray.

setup/plugins/installDatabase/SetLanguage.civi-setup.php

index 62543fd29c7a9e566a83598722f3f0adf337ecb3..0da89b6b890ce177a31481c8065289b713dcd154 100644 (file)
@@ -14,5 +14,11 @@ if (!defined('CIVI_SETUP')) {
     if ($e->getModel()->lang) {
       \Civi\Setup::log()->info('[SetLanguage.civi-setup.php] Set default language to ' . $e->getModel()->lang);
       \Civi::settings()->set('lcMessages', $e->getModel()->lang);
+
+      // Ensure that post-install messages are displayed in the new locale.
+      // Note: This arguably shouldn't be necessary since `$tsLocale` is generally setup before installation,
+      // but it may get trampled during bootstrap.
+      $domain = CRM_Core_BAO_Domain::getDomain();
+      \CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales);
     }
   }, \Civi\Setup::PRIORITY_LATE + 400);