From eb294d212fb73f0fe8fb9e4cbdfcc9cdffcf95ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 2 Mar 2022 16:16:28 +0100 Subject: [PATCH 1/9] Remove usage of legacy locale parameter --- UPGRADE.md | 25 ++++++++++ docs/reference.md | 17 +++++++ .../DependencyInjection/Configuration.php | 5 ++ .../SyliusResourceExtension.php | 2 + .../services/integrations/translation.xml | 4 +- .../Tests/Configuration/ConfigurationTest.php | 47 +++++++++++++++++++ .../SyliusResourceExtensionTest.php | 32 +++++++++++++ 7 files changed, 130 insertions(+), 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index caee12522..9303234c7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,28 @@ +## UPGRADE FOR `1.9.x` + +### FROM `1.8.x` TO `1.9.x` + +- `translations`: + +If you are using translations, the default locale provider `sylius.translation_locale_provider.immutable` is using two new translation options. + +```yaml +sylius_resource: + translation: + available_locales: ['en'] + default_locale: 'en' +``` + +Before `1.9.x` it was configured with `%locale%` parameter. +If you still use this `%locale%`parameter, you can configure translation like this: + +```yaml +sylius_resource: + translation: + available_locales: ['%locale%'] + default_locale: '%locale%' +``` + ## UPGRADE FOR `1.7.x` ### FROM `1.6.x` TO `1.7.x` diff --git a/docs/reference.md b/docs/reference.md index c0ecbf43d..104f7575c 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -2,6 +2,23 @@ ```yaml sylius_resource: + mapping: + paths: ['%kernel.project_dir%/src/Entity'] # Used for Routes with PHP attributes + translation: + enabled: true + available_locales: ['en'] + default_locale: 'en' + locale_provider: 'sylius.translation_locale_provider.immutable' + settings: + paginate: ~ + limit: ~ + allowed_paginate: [10, 20, 30] + default_page_size: 10 + sortable: false + sorting: ~ + filterable: false + criteria: ~ + state_machine_component: winzou # or symfony resources: app.book: driver: doctrine/orm diff --git a/src/Bundle/DependencyInjection/Configuration.php b/src/Bundle/DependencyInjection/Configuration.php index 1d27c7d34..27e75c8fa 100644 --- a/src/Bundle/DependencyInjection/Configuration.php +++ b/src/Bundle/DependencyInjection/Configuration.php @@ -134,6 +134,11 @@ private function addTranslationsSection(ArrayNodeDefinition $node): void ->arrayNode('translation') ->canBeDisabled() ->children() + ->arrayNode('available_locales') + ->defaultValue(['en']) + ->prototype('scalar')->end() + ->end() + ->scalarNode('default_locale')->defaultValue('en')->end() ->scalarNode('locale_provider')->defaultValue('sylius.translation_locale_provider.immutable')->cannotBeEmpty()->end() ->end() ->end() diff --git a/src/Bundle/DependencyInjection/SyliusResourceExtension.php b/src/Bundle/DependencyInjection/SyliusResourceExtension.php index fec4372ab..c483781a6 100644 --- a/src/Bundle/DependencyInjection/SyliusResourceExtension.php +++ b/src/Bundle/DependencyInjection/SyliusResourceExtension.php @@ -50,6 +50,8 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter('sylius.resource.mapping', $config['mapping']); $container->setParameter('sylius.resource.settings', $config['settings']); + $container->setParameter('sylius.resource.translation.available_locales', $config['translation']['available_locales']); + $container->setParameter('sylius.resource.translation.default_locale', $config['translation']['default_locale']); $container->setAlias('sylius.resource_controller.authorization_checker', $config['authorization_checker']); $this->loadPersistence($config['drivers'], $config['resources'], $loader); diff --git a/src/Bundle/Resources/config/services/integrations/translation.xml b/src/Bundle/Resources/config/services/integrations/translation.xml index 04ba81cc7..87d6debfb 100644 --- a/src/Bundle/Resources/config/services/integrations/translation.xml +++ b/src/Bundle/Resources/config/services/integrations/translation.xml @@ -17,9 +17,9 @@ - %locale% + %sylius.resource.translation.available_locales% - %locale% + %sylius.resource.translation.default_locale% diff --git a/src/Bundle/Tests/Configuration/ConfigurationTest.php b/src/Bundle/Tests/Configuration/ConfigurationTest.php index 4b32a5d85..16042450c 100644 --- a/src/Bundle/Tests/Configuration/ConfigurationTest.php +++ b/src/Bundle/Tests/Configuration/ConfigurationTest.php @@ -75,6 +75,53 @@ public function its_mapping_paths_can_be_customized() ); } + /** + * @test + */ + public function it_has_default_translation() + { + $this->assertProcessedConfigurationEquals( + [ + [], + ], + [ + 'translation' => [ + 'enabled' => true, + 'available_locales' => ['en'], + 'default_locale' => 'en', + 'locale_provider' => 'sylius.translation_locale_provider.immutable', + ], + ], + 'translation' + ); + } + + /** + * @test + */ + public function its_translation_can_be_customized() + { + $this->assertProcessedConfigurationEquals( + [ + ['translation' => [ + 'enabled' => false, + 'available_locales' => ['fr', 'pl'], + 'default_locale' => 'fr', + 'locale_provider' => 'app.locale_provider.custom', + ]], + ], + [ + 'translation' => [ + 'enabled' => false, + 'available_locales' => ['fr', 'pl'], + 'default_locale' => 'fr', + 'locale_provider' => 'app.locale_provider.custom', + ], + ], + 'translation' + ); + } + /** * @test */ diff --git a/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php b/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php index 5569ce293..9c45dec28 100644 --- a/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php +++ b/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php @@ -69,6 +69,38 @@ public function it_aliases_authorization_checker_with_the_one_given_in_configura $this->assertContainerBuilderHasAlias('sylius.resource_controller.authorization_checker', 'custom_service'); } + /** + * @test + */ + public function it_registers_translation_available_locales_parameter() + { + $this->setParameter('kernel.bundles', []); + + $this->load([ + 'translation' => [ + 'available_locales' => ['fr', 'pl'], + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.available_locales', ['fr', 'pl']); + } + + /** + * @test + */ + public function it_registers_translation_default_locale_parameter() + { + $this->setParameter('kernel.bundles', []); + + $this->load([ + 'translation' => [ + 'default_locale' => 'fr', + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.default_locale', 'fr'); + } + /** * @test */ From 9d5e42294821a04d0650cbb3742080f2ef6b7782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 10:56:02 +0100 Subject: [PATCH 2/9] Improve DX with existing parameters --- UPGRADE.md | 16 +++- docs/reference.md | 2 +- .../DependencyInjection/Configuration.php | 6 +- .../SyliusResourceExtension.php | 67 +++++++++++++++- .../services/integrations/translation.xml | 2 +- .../Tests/Configuration/ConfigurationTest.php | 27 +++---- .../SyliusResourceExtensionTest.php | 78 +++++++++++++++++-- 7 files changed, 170 insertions(+), 28 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 9303234c7..6c4ecaacf 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,8 +9,8 @@ If you are using translations, the default locale provider `sylius.translation_l ```yaml sylius_resource: translation: - available_locales: ['en'] - default_locale: 'en' + enabled_locales: [] + default_locale: null ``` Before `1.9.x` it was configured with `%locale%` parameter. @@ -19,7 +19,17 @@ If you still use this `%locale%`parameter, you can configure translation like th ```yaml sylius_resource: translation: - available_locales: ['%locale%'] + enabled_locales: ['%locale%'] + default_locale: '%locale%' +``` + +If you still use this `%kernel.default_locale%` and `%kernel.enabled_locales%` parameters, you can configure translation like this: + + +```yaml +sylius_resource: + translation: + enabled_locales: ['%locale%'] default_locale: '%locale%' ``` diff --git a/docs/reference.md b/docs/reference.md index 104f7575c..ac18e9caa 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -6,7 +6,7 @@ sylius_resource: paths: ['%kernel.project_dir%/src/Entity'] # Used for Routes with PHP attributes translation: enabled: true - available_locales: ['en'] + enabled_locales: ['en'] default_locale: 'en' locale_provider: 'sylius.translation_locale_provider.immutable' settings: diff --git a/src/Bundle/DependencyInjection/Configuration.php b/src/Bundle/DependencyInjection/Configuration.php index 27e75c8fa..02836fefb 100644 --- a/src/Bundle/DependencyInjection/Configuration.php +++ b/src/Bundle/DependencyInjection/Configuration.php @@ -134,11 +134,11 @@ private function addTranslationsSection(ArrayNodeDefinition $node): void ->arrayNode('translation') ->canBeDisabled() ->children() - ->arrayNode('available_locales') - ->defaultValue(['en']) + ->arrayNode('enabled_locales') + ->defaultValue([]) ->prototype('scalar')->end() ->end() - ->scalarNode('default_locale')->defaultValue('en')->end() + ->scalarNode('default_locale')->defaultNull()->end() ->scalarNode('locale_provider')->defaultValue('sylius.translation_locale_provider.immutable')->cannotBeEmpty()->end() ->end() ->end() diff --git a/src/Bundle/DependencyInjection/SyliusResourceExtension.php b/src/Bundle/DependencyInjection/SyliusResourceExtension.php index c483781a6..03e7d6bac 100644 --- a/src/Bundle/DependencyInjection/SyliusResourceExtension.php +++ b/src/Bundle/DependencyInjection/SyliusResourceExtension.php @@ -46,12 +46,11 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('services/integrations/translation.xml'); $container->setAlias('sylius.translation_locale_provider', $config['translation']['locale_provider'])->setPublic(true); + $this->createTranslationParameters($config, $container); } $container->setParameter('sylius.resource.mapping', $config['mapping']); $container->setParameter('sylius.resource.settings', $config['settings']); - $container->setParameter('sylius.resource.translation.available_locales', $config['translation']['available_locales']); - $container->setParameter('sylius.resource.translation.default_locale', $config['translation']['default_locale']); $container->setAlias('sylius.resource_controller.authorization_checker', $config['authorization_checker']); $this->loadPersistence($config['drivers'], $config['resources'], $loader); @@ -137,4 +136,68 @@ private function loadResources(array $loadedResources, ContainerBuilder $contain } } } + + private function createTranslationParameters(array $config, ContainerBuilder $container): void + { + $this->createEnabledLocalesParameter($config, $container); + $this->createDefaultLocaleParameter($config, $container); + } + + private function createEnabledLocalesParameter(array $config, ContainerBuilder $container): void + { + $enabledLocales = $config['translation']['enabled_locales']; + + if (count($enabledLocales) > 0) { + $container->setParameter('sylius.resource.translation.enabled_locales', $enabledLocales); + + return; + } + + if ($container->hasParameter('locale')) { + $container->setParameter('sylius.resource.translation.enabled_locales', [$container->getParameter('locale')]); + + return; + } + + if ($container->hasParameter('kernel.enabled_locales')) { + $kernelEnabledLocales = $container->getParameter('kernel.enabled_locales'); + + if (count($kernelEnabledLocales) > 0) { + $container->setParameter('sylius.resource.translation.enabled_locales', $container->getParameter('kernel.enabled_locales')); + + return; + } + } + + $container->setParameter('sylius.resource.translation.enabled_locales', ['en']); + } + + private function createDefaultLocaleParameter(array $config, ContainerBuilder $container): void + { + $defaultLocale = $config['translation']['default_locale']; + + if (is_string($defaultLocale)) { + $container->setParameter('sylius.resource.translation.default_locale', $defaultLocale); + + return; + } + + if ($container->hasParameter('locale')) { + $container->setParameter('sylius.resource.translation.default_locale', $container->getParameter('locale')); + + return; + } + + if ($container->hasParameter('kernel.default_locale')) { + $kernelDefaultLocale = $container->getParameter('kernel.default_locale'); + + if (is_string($kernelDefaultLocale)) { + $container->setParameter('sylius.resource.translation.default_locale', $kernelDefaultLocale); + + return; + } + } + + $container->setParameter('sylius.resource.translation.default_locale', 'en'); + } } diff --git a/src/Bundle/Resources/config/services/integrations/translation.xml b/src/Bundle/Resources/config/services/integrations/translation.xml index 87d6debfb..19b5866b1 100644 --- a/src/Bundle/Resources/config/services/integrations/translation.xml +++ b/src/Bundle/Resources/config/services/integrations/translation.xml @@ -17,7 +17,7 @@ - %sylius.resource.translation.available_locales% + %sylius.resource.translation.enabled_locales% %sylius.resource.translation.default_locale% diff --git a/src/Bundle/Tests/Configuration/ConfigurationTest.php b/src/Bundle/Tests/Configuration/ConfigurationTest.php index 16042450c..163e1d911 100644 --- a/src/Bundle/Tests/Configuration/ConfigurationTest.php +++ b/src/Bundle/Tests/Configuration/ConfigurationTest.php @@ -16,6 +16,7 @@ use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; use PHPUnit\Framework\TestCase; use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration; +use Symfony\Component\Config\Definition\ConfigurationInterface; class ConfigurationTest extends TestCase { @@ -24,7 +25,7 @@ class ConfigurationTest extends TestCase /** * @test */ - public function it_does_not_break_if_not_customized() + public function it_does_not_break_if_not_customized(): void { $this->assertConfigurationIsValid( [ @@ -36,7 +37,7 @@ public function it_does_not_break_if_not_customized() /** * @test */ - public function it_has_default_mapping_paths() + public function it_has_default_mapping_paths(): void { $this->assertProcessedConfigurationEquals( [ @@ -56,7 +57,7 @@ public function it_has_default_mapping_paths() /** * @test */ - public function its_mapping_paths_can_be_customized() + public function its_mapping_paths_can_be_customized(): void { $this->assertProcessedConfigurationEquals( [ @@ -78,7 +79,7 @@ public function its_mapping_paths_can_be_customized() /** * @test */ - public function it_has_default_translation() + public function it_has_default_translation(): void { $this->assertProcessedConfigurationEquals( [ @@ -87,8 +88,8 @@ public function it_has_default_translation() [ 'translation' => [ 'enabled' => true, - 'available_locales' => ['en'], - 'default_locale' => 'en', + 'enabled_locales' => [], + 'default_locale' => null, 'locale_provider' => 'sylius.translation_locale_provider.immutable', ], ], @@ -99,13 +100,13 @@ public function it_has_default_translation() /** * @test */ - public function its_translation_can_be_customized() + public function its_translation_can_be_customized(): void { $this->assertProcessedConfigurationEquals( [ ['translation' => [ 'enabled' => false, - 'available_locales' => ['fr', 'pl'], + 'enabled_locales' => ['fr', 'pl'], 'default_locale' => 'fr', 'locale_provider' => 'app.locale_provider.custom', ]], @@ -113,7 +114,7 @@ public function its_translation_can_be_customized() [ 'translation' => [ 'enabled' => false, - 'available_locales' => ['fr', 'pl'], + 'enabled_locales' => ['fr', 'pl'], 'default_locale' => 'fr', 'locale_provider' => 'app.locale_provider.custom', ], @@ -125,7 +126,7 @@ public function its_translation_can_be_customized() /** * @test */ - public function it_has_default_authorization_checker() + public function it_has_default_authorization_checker(): void { $this->assertProcessedConfigurationEquals( [ @@ -139,7 +140,7 @@ public function it_has_default_authorization_checker() /** * @test */ - public function its_authorization_checker_can_be_customized() + public function its_authorization_checker_can_be_customized(): void { $this->assertProcessedConfigurationEquals( [ @@ -153,7 +154,7 @@ public function its_authorization_checker_can_be_customized() /** * @test */ - public function its_authorization_checker_cannot_be_empty() + public function its_authorization_checker_cannot_be_empty(): void { $this->assertPartialConfigurationIsInvalid( [ @@ -163,7 +164,7 @@ public function its_authorization_checker_cannot_be_empty() ); } - protected function getConfiguration() + protected function getConfiguration(): ConfigurationInterface { return new Configuration(); } diff --git a/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php b/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php index 9c45dec28..c981502d6 100644 --- a/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php +++ b/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php @@ -72,23 +72,91 @@ public function it_aliases_authorization_checker_with_the_one_given_in_configura /** * @test */ - public function it_registers_translation_available_locales_parameter() + public function it_registers_translation_enabled_locales_parameter_from_locale_parameter(): void { $this->setParameter('kernel.bundles', []); + $this->setParameter('locale', 'pl'); $this->load([ 'translation' => [ - 'available_locales' => ['fr', 'pl'], + 'enabled_locales' => [], ], ]); - $this->assertContainerBuilderHasParameter('sylius.resource.translation.available_locales', ['fr', 'pl']); + $this->assertContainerBuilderHasParameter('sylius.resource.translation.enabled_locales', ['pl']); } /** * @test */ - public function it_registers_translation_default_locale_parameter() + public function it_registers_translation_enabled_locales_parameter_from_kernel_enabled_locales_parameter(): void + { + $this->setParameter('kernel.bundles', []); + $this->setParameter('kernel.enabled_locales', ['fr', 'pl']); + + $this->load([ + 'translation' => [ + 'enabled_locales' => [], + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.enabled_locales', ['fr', 'pl']); + } + + /** + * @test + */ + public function it_registers_translation_enabled_locales_parameter(): void + { + $this->setParameter('kernel.bundles', []); + + $this->load([ + 'translation' => [ + 'enabled_locales' => ['fr', 'pl'], + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.enabled_locales', ['fr', 'pl']); + } + + /** + * @test + */ + public function it_registers_default_locale_parameter_from_locale_parameter(): void + { + $this->setParameter('kernel.bundles', []); + $this->setParameter('locale', 'pl'); + + $this->load([ + 'translation' => [ + 'default_locale' => null, + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.default_locale', 'pl'); + } + + /** + * @test + */ + public function it_registers_default_locale_parameter_from_kernel_default_locale_parameter(): void + { + $this->setParameter('kernel.bundles', []); + $this->setParameter('kernel.default_locale', 'pl'); + + $this->load([ + 'translation' => [ + 'default_locale' => null, + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.default_locale', 'pl'); + } + + /** + * @test + */ + public function it_registers_translation_default_locale_parameter(): void { $this->setParameter('kernel.bundles', []); @@ -104,7 +172,7 @@ public function it_registers_translation_default_locale_parameter() /** * @test */ - public function it_registers_default_translation_parameters() + public function it_registers_default_translation_parameters(): void { // TODO: Move ResourceGrid integration to a dedicated compiler pass $this->setParameter('kernel.bundles', []); From c5ab2ed6c46e49557eb770b6108ed8d57b82ca38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 10:58:31 +0100 Subject: [PATCH 3/9] Fix README --- UPGRADE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 6c4ecaacf..cc0032b04 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -23,14 +23,14 @@ sylius_resource: default_locale: '%locale%' ``` -If you still use this `%kernel.default_locale%` and `%kernel.enabled_locales%` parameters, you can configure translation like this: +If you use `%kernel.default_locale%` and `%kernel.enabled_locales%` parameters, you can configure translation like this: ```yaml sylius_resource: translation: - enabled_locales: ['%locale%'] - default_locale: '%locale%' + enabled_locales: '%kernel.enabled_locales%' + default_locale: '%kernel.default_locale%' ``` ## UPGRADE FOR `1.7.x` From 9a9cbbe80109deb12f7baf981ce0888486d212c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 10:59:52 +0100 Subject: [PATCH 4/9] Use kernel parameters on configuration reference --- docs/reference.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference.md b/docs/reference.md index ac18e9caa..07d77da00 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -6,8 +6,8 @@ sylius_resource: paths: ['%kernel.project_dir%/src/Entity'] # Used for Routes with PHP attributes translation: enabled: true - enabled_locales: ['en'] - default_locale: 'en' + enabled_locales: '%kernel.enabled_locales%' + default_locale: '%kernel.default_locale%' locale_provider: 'sylius.translation_locale_provider.immutable' settings: paginate: ~ From 9acdc420500b2326232fe1d9a1dab8884cbb5a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 11:03:14 +0100 Subject: [PATCH 5/9] Fix PHPStan errors --- src/Bundle/DependencyInjection/SyliusResourceExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/DependencyInjection/SyliusResourceExtension.php b/src/Bundle/DependencyInjection/SyliusResourceExtension.php index 03e7d6bac..9f7573017 100644 --- a/src/Bundle/DependencyInjection/SyliusResourceExtension.php +++ b/src/Bundle/DependencyInjection/SyliusResourceExtension.php @@ -160,7 +160,7 @@ private function createEnabledLocalesParameter(array $config, ContainerBuilder $ } if ($container->hasParameter('kernel.enabled_locales')) { - $kernelEnabledLocales = $container->getParameter('kernel.enabled_locales'); + $kernelEnabledLocales = (array) $container->getParameter('kernel.enabled_locales'); if (count($kernelEnabledLocales) > 0) { $container->setParameter('sylius.resource.translation.enabled_locales', $container->getParameter('kernel.enabled_locales')); From b9dec16d9ad3217fb5ae87f3b6391e608d457483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 11:10:52 +0100 Subject: [PATCH 6/9] Add missing tests with default values --- .../SyliusResourceExtensionTest.php | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php b/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php index c981502d6..bd383727f 100644 --- a/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php +++ b/src/Bundle/Tests/DependencyInjection/SyliusResourceExtensionTest.php @@ -106,7 +106,7 @@ public function it_registers_translation_enabled_locales_parameter_from_kernel_e /** * @test */ - public function it_registers_translation_enabled_locales_parameter(): void + public function it_registers_translation_enabled_locales_parameter_with_given_locales(): void { $this->setParameter('kernel.bundles', []); @@ -119,6 +119,22 @@ public function it_registers_translation_enabled_locales_parameter(): void $this->assertContainerBuilderHasParameter('sylius.resource.translation.enabled_locales', ['fr', 'pl']); } + /** + * @test + */ + public function it_registers_translation_enabled_locales_parameter(): void + { + $this->setParameter('kernel.bundles', []); + + $this->load([ + 'translation' => [ + 'enabled_locales' => [], + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.enabled_locales', ['en']); + } + /** * @test */ @@ -156,7 +172,7 @@ public function it_registers_default_locale_parameter_from_kernel_default_locale /** * @test */ - public function it_registers_translation_default_locale_parameter(): void + public function it_registers_translation_default_locale_parameter_with_given_locale(): void { $this->setParameter('kernel.bundles', []); @@ -169,6 +185,22 @@ public function it_registers_translation_default_locale_parameter(): void $this->assertContainerBuilderHasParameter('sylius.resource.translation.default_locale', 'fr'); } + /** + * @test + */ + public function it_registers_translation_default_locale_parameter(): void + { + $this->setParameter('kernel.bundles', []); + + $this->load([ + 'translation' => [ + 'default_locale' => null, + ], + ]); + + $this->assertContainerBuilderHasParameter('sylius.resource.translation.default_locale', 'en'); + } + /** * @test */ From db1f0264bb7f2997a351cfe3ef50959e5141b4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 15:15:39 +0100 Subject: [PATCH 7/9] Update UPGRADE.md Co-authored-by: Victor Vasiloi --- UPGRADE.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index cc0032b04..5c02542a6 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -4,7 +4,7 @@ - `translations`: -If you are using translations, the default locale provider `sylius.translation_locale_provider.immutable` is using two new translation options. +New configuration options were introduced to set the default and the defined (enabled) locales used by the default translation locale provider (`sylius.translation_locale_provider.immutable` service): ```yaml sylius_resource: @@ -13,8 +13,10 @@ sylius_resource: default_locale: null ``` -Before `1.9.x` it was configured with `%locale%` parameter. -If you still use this `%locale%`parameter, you can configure translation like this: +Before version `1.9.x` the provider was configured with `locale` parameter. +If those options are not configured, for backward compatibility, it will fallback to the `locale` parameter if it's defined. +This is deprecated and will be removed in version 2.0. +If you want to keep using the `locale` parameter starting with version 2.0, then add the following configuration: ```yaml sylius_resource: @@ -23,13 +25,13 @@ sylius_resource: default_locale: '%locale%' ``` -If you use `%kernel.default_locale%` and `%kernel.enabled_locales%` parameters, you can configure translation like this: +Starting with version 2.0, the default values will be set from `kernel.default_locale` and `kernel.enabled_locales` parameters. ```yaml sylius_resource: translation: - enabled_locales: '%kernel.enabled_locales%' + enabled_locales: ['%kernel.enabled_locales%'] default_locale: '%kernel.default_locale%' ``` From 1c26d09a16853ccab52f7c195ca2e0f4d2f334f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 15:47:22 +0100 Subject: [PATCH 8/9] Add some deprecation notices --- UPGRADE.md | 1 - src/Bundle/DependencyInjection/SyliusResourceExtension.php | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index 5c02542a6..cba340be3 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -27,7 +27,6 @@ sylius_resource: Starting with version 2.0, the default values will be set from `kernel.default_locale` and `kernel.enabled_locales` parameters. - ```yaml sylius_resource: translation: diff --git a/src/Bundle/DependencyInjection/SyliusResourceExtension.php b/src/Bundle/DependencyInjection/SyliusResourceExtension.php index 9f7573017..9e7570c01 100644 --- a/src/Bundle/DependencyInjection/SyliusResourceExtension.php +++ b/src/Bundle/DependencyInjection/SyliusResourceExtension.php @@ -154,6 +154,8 @@ private function createEnabledLocalesParameter(array $config, ContainerBuilder $ } if ($container->hasParameter('locale')) { + trigger_deprecation('sylius/resource-bundle', '1.9', 'Locale parameter usage to defined the enabled locales will no longer used in 2.0, you should use %kernel.enabled_locales% instead.'); + $container->setParameter('sylius.resource.translation.enabled_locales', [$container->getParameter('locale')]); return; @@ -183,6 +185,8 @@ private function createDefaultLocaleParameter(array $config, ContainerBuilder $c } if ($container->hasParameter('locale')) { + trigger_deprecation('sylius/resource-bundle', '1.9', 'Locale parameter usage to define the translation default locale will no longer used in 2.0, you should use %kernel.default_locale% instead.'); + $container->setParameter('sylius.resource.translation.default_locale', $container->getParameter('locale')); return; From 9737c93cee033867ee834c1ebb9aaf15a33008c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 3 Mar 2022 15:51:24 +0100 Subject: [PATCH 9/9] Improve translation configuration for enabled locales --- .../Resources/config/services/integrations/translation.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Bundle/Resources/config/services/integrations/translation.xml b/src/Bundle/Resources/config/services/integrations/translation.xml index 19b5866b1..dfeb6753b 100644 --- a/src/Bundle/Resources/config/services/integrations/translation.xml +++ b/src/Bundle/Resources/config/services/integrations/translation.xml @@ -16,9 +16,7 @@ - - %sylius.resource.translation.enabled_locales% - + %sylius.resource.translation.enabled_locales% %sylius.resource.translation.default_locale%