-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[String] Add locale-sensitive map for slugging symbols #36456
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
[String] Add locale-sensitive map for slugging symbols #36456
Conversation
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 not sure we need an options array for this, let's pass a map directly.
The map should be locale-sensitive and the current map should be used only with an English locale IMHO.
I modify the PR as i understand of your recommandations @nicolas-grekas ;) thank you for your feedbacks |
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.
Wow, I like this feature.
But what if the $locale
is fr
and I use the default $charsReplacement = ['en' => ['@' => 'at', '&' => 'and']]
. Then nothing will be slugged, right?
Does it make sense to be more complex here? Maybe dedicate this replacement thing to a separate class?
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.
This should be a constructor argument, not a method argument. The argument should default to null and the default value be set on the property I think.
But what if the $locale is fr and I use the default $charsReplacement = ['en' => ['@' => 'at', '&' => 'and']]. Then nothing will be slugged, right?
Yes, that's the expected behavior to me.
Does it make sense to be more complex here? Maybe dedicate this replacement thing to a separate class?
Getting more complex is always possible by implementing SluggerInterface. Since the AsciiSlugger
already does these simple mappings, I think it makes sense to make the map locale-aware (as the class already is).
There is still one question remaining here: how will people take advantage of the new argument in a Symfony app? How will they configure the map? Do we need tighter integration? |
@nicolas-grekas i have fixed your feedbacks, thank you for your reviews |
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 fixed my last comments. About the idea to use a translator, or how this could be leveraged from framework-bundle, we don't have to decide now. Let's wait for someone interested in resolving these challenges. Good as is on my side.
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.
Thank you
Thank you @lmasforne. |
Am I right that there is no way to configure the `$ymbolsMap` when using the Symfony framework integration (i.e. dependency injection)? What about adding a public method for this? The feature to set it in the constructor was added in symfony#36456
By default chars '@' and '&' are respectively replaced by 'at' and 'and' (so limited by enlgish language).
I had an $options arguments to 'slug' method to replace chars with your own logic.