From 71be6de97df74807c0eeb2e848ec752366b246b5 Mon Sep 17 00:00:00 2001 From: Artem Siminenko Date: Tue, 11 Jul 2023 12:55:36 +0200 Subject: [PATCH] CC-28482: Fixed Backoffice and Marketplace translations. (#10290) CC-28482 Fixed Backoffice and Marketplace translations --- .../LocaleCommunicationFactory.php | 11 ++++++ .../Application/LocaleApplicationPlugin.php | 20 ++++++++++- .../Zed/Locale/LocaleDependencyProvider.php | 35 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/Spryker/Zed/Locale/Communication/LocaleCommunicationFactory.php b/src/Spryker/Zed/Locale/Communication/LocaleCommunicationFactory.php index 91251fa..3bf3616 100644 --- a/src/Spryker/Zed/Locale/Communication/LocaleCommunicationFactory.php +++ b/src/Spryker/Zed/Locale/Communication/LocaleCommunicationFactory.php @@ -7,6 +7,7 @@ namespace Spryker\Zed\Locale\Communication; +use Spryker\Shared\Kernel\Store; use Spryker\Shared\LocaleExtension\Dependency\Plugin\LocalePluginInterface; use Spryker\Zed\Kernel\Communication\AbstractCommunicationFactory; use Spryker\Zed\Locale\Dependency\Facade\LocaleToStoreFacadeInterface; @@ -35,4 +36,14 @@ public function getStoreFacade(): LocaleToStoreFacadeInterface { return $this->getProvidedDependency(LocaleDependencyProvider::FACADE_STORE); } + + /** + * @deprecated Will be removed after dynamic multi-store is always enabled. + * + * @return \Spryker\Shared\Kernel\Store + */ + public function getStore(): Store + { + return $this->getProvidedDependency(LocaleDependencyProvider::STORE); + } } diff --git a/src/Spryker/Zed/Locale/Communication/Plugin/Application/LocaleApplicationPlugin.php b/src/Spryker/Zed/Locale/Communication/Plugin/Application/LocaleApplicationPlugin.php index ac46447..203e18f 100644 --- a/src/Spryker/Zed/Locale/Communication/Plugin/Application/LocaleApplicationPlugin.php +++ b/src/Spryker/Zed/Locale/Communication/Plugin/Application/LocaleApplicationPlugin.php @@ -45,10 +45,28 @@ public function provide(ContainerInterface $container): ContainerInterface $container->set(static::BC_FEATURE_FLAG_LOCALE_LISTENER, false); $container->set(static::SERVICE_LOCALE, function (ContainerInterface $container): string { $localeTransfer = $this->getFactory()->getLocalePlugin()->getLocaleTransfer($container); + $localeName = $localeTransfer->getLocaleNameOrFail(); + $this->setStoreCurrentLocale($localeName); - return $localeTransfer->getLocaleNameOrFail(); + return $localeName; }); return $container; } + + /** + * @deprecated Will be removed after dynamic multi-store is always enabled. + * + * @param string $localeName + * + * @return void + */ + protected function setStoreCurrentLocale(string $localeName): void + { + if ($this->getFactory()->getStoreFacade()->isDynamicStoreEnabled()) { + return; + } + + $this->getFactory()->getStore()->setCurrentLocale($localeName); + } } diff --git a/src/Spryker/Zed/Locale/LocaleDependencyProvider.php b/src/Spryker/Zed/Locale/LocaleDependencyProvider.php index 4be01e9..ae0eb1a 100644 --- a/src/Spryker/Zed/Locale/LocaleDependencyProvider.php +++ b/src/Spryker/Zed/Locale/LocaleDependencyProvider.php @@ -8,6 +8,7 @@ namespace Spryker\Zed\Locale; use Orm\Zed\Store\Persistence\SpyStoreQuery; +use Spryker\Shared\Kernel\Store; use Spryker\Shared\LocaleExtension\Dependency\Plugin\LocalePluginInterface; use Spryker\Zed\Kernel\AbstractBundleDependencyProvider; use Spryker\Zed\Kernel\Container; @@ -39,6 +40,13 @@ class LocaleDependencyProvider extends AbstractBundleDependencyProvider */ public const PROPEL_QUERY_STORE = 'PROPEL_QUERY_STORE'; + /** + * @deprecated Will be removed after dynamic multi-store is always enabled. + * + * @var string + */ + public const STORE = 'STORE'; + /** * @var string */ @@ -53,6 +61,7 @@ public function provideCommunicationLayerDependencies(Container $container): Con { $container = $this->addLocalePlugin($container); $container = $this->addStoreFacade($container); + $container = $this->addStore($container); return $container; } @@ -140,6 +149,32 @@ protected function addCurrentLocale(Container $container): Container return $container; } + /** + * @deprecated Exists for BC-reasons only. + * + * @param \Spryker\Zed\Kernel\Container $container + * + * @return \Spryker\Zed\Kernel\Container + */ + protected function addStore(Container $container): Container + { + $container->set(static::STORE, function () { + return $this->getStore(); + }); + + return $container; + } + + /** + * @deprecated Exists for BC-reasons only. + * + * @return \Spryker\Shared\Kernel\Store + */ + protected function getStore(): Store + { + return Store::getInstance(); + } + /** * @param \Spryker\Zed\Kernel\Container $container *