-
-
Notifications
You must be signed in to change notification settings - Fork 169
Remove usage of legacy locale parameter #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.10
Are you sure you want to change the base?
Changes from all commits
eb294d2
9d5e422
c5ab2ed
9a9cbbe
9acdc42
b9dec16
db1f026
1c26d09
9737c93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,7 @@ 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']); | |||||||||||
|
|
@@ -135,4 +136,72 @@ 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')) { | |||||||||||
| 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')]); | |||||||||||
|
|
|||||||||||
|
Zales0123 marked this conversation as resolved.
|
|||||||||||
| return; | |||||||||||
| } | |||||||||||
|
|
|||||||||||
| if ($container->hasParameter('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')); | |||||||||||
|
|
|||||||||||
| 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')) { | |||||||||||
| 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')); | |||||||||||
|
|
|||||||||||
|
Zales0123 marked this conversation as resolved.
|
|||||||||||
| 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'); | |||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I see, previously it was only a %locale% parameter. Dit it fallback previously to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a BC layer, so throwing an exception here defies the purpose of this code.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about it as well. What is more, it is bumped by the fact that we do not have tests for more than one config present here and a description of winning strategy (for now it is: 1. new resource config, 2. previous parameter, 3. Symfony parameter, 4. "en"). Another concern is that we are replacing the old parameter with the new one entirely, but both configurations may (and probably should) work together. This parameter is used in several places. This is the screenshot from the current version of Sylius-Standard: So now - the best config would be to have What I would recommend is as follows - the Anyway, I'm also lacking the cases I've described exposed as configuration tests + test drive with the current Sylius and/or Sylius-Standard to check the correctness of the new solution.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have revisited this and I agree that it needs some changes.
There's a 5th scenario, which is a combination of the 4th scenario with Symfony 4.4, which does not have the To achieve the above, the following modifications must be made to the currently proposed changes:
WDYT?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vvasiloi Thank you, this is an awesome explanation. I think your suggested change is perfect. |
|||||||||||
| } | |||||||||||
| } | |||||||||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand all of these parameters were missing, but it would be more ordered if we add only
enabled_localesanddefault_localehere and the rest of them in a separate PR 😄 #beingPettyIsMyPassion