From 16e0bd4d094264fd00d0af86180bde4e0c73b4be Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Wed, 11 Nov 2020 09:53:31 +0800 Subject: [PATCH] Move theme localization to the boot process. (#5349) It appears that doing this in the "register" process can result, at times, in an exception to be thrown as the connection to the DB is not yet established. --- modules/cms/ServiceProvider.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/cms/ServiceProvider.php b/modules/cms/ServiceProvider.php index 0749923f3..160bf8bc3 100644 --- a/modules/cms/ServiceProvider.php +++ b/modules/cms/ServiceProvider.php @@ -44,7 +44,6 @@ class ServiceProvider extends ModuleServiceProvider $this->registerBackendPermissions(); $this->registerBackendWidgets(); $this->registerBackendSettings(); - $this->registerBackendLocalization(); } } @@ -59,6 +58,10 @@ class ServiceProvider extends ModuleServiceProvider $this->bootMenuItemEvents(); $this->bootRichEditorEvents(); + + if (App::runningInBackend()) { + $this->bootBackendLocalization(); + } } /** @@ -303,16 +306,16 @@ class ServiceProvider extends ModuleServiceProvider } /** - * Registers localization from an active theme for backend items. + * Boots localization from an active theme for backend items. */ - protected function registerBackendLocalization() + protected function bootBackendLocalization() { $theme = CmsTheme::getActiveTheme(); $langPath = $theme->getPath() . '/lang'; if (File::isDirectory($langPath)) { - Lang::addNamespace("themes.{$theme->getId()}", $langPath); + Lang::addNamespace('themes.' . $theme->getId(), $langPath); } }