Localized Passthrough Locale for #[Route()] #53571
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As per reference of #53539, I was looking for a way to solve:
https://stackoverflow.com/questions/41721408/symfony-default-locale-without-specifying-in-url/77819142
Currently the first path (either specifying a path, or a path array) the first path index is 0 in AttributeClassLoader.php. Taking advantage of this, my answer in the Stack Overflow and in #53539 works, but is not advised as this is not documented. My PR adds support for:
Which adds the path as 'action' and 'action.nl', means the
{_locale}
can be used to catch all other locales. As @xabbuh and I talked about. Using this:Is still allowed as the first array index of 0 was always allowed anyway (as the Route would turn the
$path
into$paths[]
), and should remain to not break backwards compatibility with anyone using it, but if1 =>
etc (integer array keys) used, it will raise an exception (also tested in the Tests).If you guys could look this over that would be great. If someone needs any clarification for anyone wanting to document this feature near https://symfony.com/doc/current/routing.html#localized-routes-i18n that also would be great!