Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[HttpKernel][Framework] Locale aware services#28929
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ro0NL left a comment
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 think this is a nice approach/feature :)
src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DependencyInjection/RegisterLocaleAwareServicesPass.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ro0NL left a comment
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.
the autoconfiguration should also be updated (each service being an instance of LocaleAwareInterface should get thelocale_aware tag automatically.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ro0NL commentedOct 28, 2018
curious.. what about using the existing cc@stof |
javiereguiluz commentedNov 7, 2018
@neghmurken this is an interesting proposal! Thanks for contributing it. If this is decided to be merged, we'd need some examples of how can we use this new feature in practice (inside a Symfony app and/or as a stand-alone component). If this feature improves an existing feature, please show a before/after example. Thanks a lot! |
nicolas-grekas left a comment
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'm mixed here:
- on one side this is very pragmatic;
- on the other side, this is building on top of service mutation - while services should be stateless.
I'd very prefer we could think about a stateless approach instead.
src/Symfony/Component/HttpKernel/DependencyInjection/RegisterLocaleAwareServicesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DependencyInjection/RegisterLocaleAwareServicesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…Interface (nicolas-grekas)This PR was merged into the 4.2 branch.Discussion----------[Contracts] extract LocaleAwareInterface out of TranslatorInterface| Q | A| ------------- | ---| Branch? | 4.2| Bug fix? | yes| New feature? | no| BC breaks? | yes| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -While reviewing#28929, I realized we have a design issue in the Translation contract: we missed segregating `setLocale()`/`getLocale()` out of `TranslatorInterface`. E.g. when people type-hint for `TranslatorInterface`, they *should not* be auto-suggested with the `setLocale()` mutator.Technically, that's a BC break. I think we should do it. The release is close enough in time and that will save us from maintenance issues this will create in the future otherwise.Commits-------73e4a1a [Contracts] extract LocaleAwareInterface out of TranslatorInterface
nicolas-grekas commentedDec 13, 2018
I completely swapped my mind here and actually, we merged Would you mind rebasing, please? |
nicolas-grekas left a comment
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.
thanks, here are some comments to help move forward.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DependencyInjection/RegisterLocaleAwareServicesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/DependencyInjection/RegisterLocaleAwareServicesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedJan 26, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Small rebase needed + lowest version of httpkernel should be bumped in framework bundle to make tests pass. |
src/Symfony/Component/HttpKernel/DependencyInjection/RegisterLocaleAwareServicesPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| <argumenttype="service"id="Psr\Container\ContainerInterface" /> | ||
| </service> | ||
| <serviceid="translator_listener"class="Symfony\Component\HttpKernel\EventListener\TranslatorListener"> |
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.
Should we deprecate the service instead in case someone is relying on its presence?
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.
How can we deprecate without it conflicting with the newLocaleAwareListener ?
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.
Does it do any harm if both listeners are executed?
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.
Yeah you're right. There is no undesirable side effect beside setting the locale twice
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 removed thetranslator_listener service completely as keeping it would trigger deprecation notices. I don't think that's an issue.
xabbuh left a comment
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.
looks good apart from a few remaining minor comments
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...mfony/Component/HttpKernel/Tests/DependencyInjection/RegisterLocaleAwareServicesPassTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Green. I rebased this PR on latest master and made some tweaks to polish it. I removed thetranslator_listener service completely as keeping it would trigger deprecation notices. I don't think that's an issue.
fabpot commentedApr 3, 2019
Thank you@neghmurken. |
…ken)This PR was merged into the 4.3-dev branch.Discussion----------[HttpKernel][Framework] Locale aware services| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |Added a `LocaleAwareInterface` (and also a new service tag `kernel.locale_aware`) to be implemented on services that require the current locale at request time.Also, refactored the actual Translator service to implement the overmentioned interfaceTodo :* [ ] Documention PR (will be written after some feedback)Commits-------b9ac645 Locale aware service registration
winzou commentedOct 28, 2019
Hello@neghmurken,@nicolas-grekas My usecase:
In the if I pasted, during the This was not mentionned in the changelog and looks like a BC break (and a bug?) to me. Am I missing something? Thanks for your insights! |
xabbuh commentedOct 28, 2019
@winzou Would you mind opening a new issue with your insights? Otherwise I am afraid that your input is likely to get lost. |
Uh oh!
There was an error while loading.Please reload this page.
Added a
LocaleAwareInterface(and also a new service tagkernel.locale_aware) to be implemented on services that require the current locale at request time.Also, refactored the actual Translator service to implement the overmentioned interface
Todo :