[wp-trac] [WordPress Trac] #54415: remove_accent does not remove accents
WordPress Trac
noreply at wordpress.org
Fri Nov 12 08:38:33 UTC 2021
#54415: remove_accent does not remove accents
-----------------------------------------+------------------------------
Reporter: malthert | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback has-patch | Focuses:
-----------------------------------------+------------------------------
Comment (by malthert):
Replying to [comment:9 SergeyBiryukov]:
> Sounds good to me, let's just check for any de_* locale.
Ok, will check for "de" locale (since "de" without trailing underscore is
technically valid too, and there are no 3 letter locales starting with
"de" so it's safe in this regard too https://www.localeplanet.com/icu/)
> > 2) the letter "ß" is only used in German languages anyway and there is
no transliteration of ß => s to be found anywhere.
> > This will be removed from the conditional and update the "general"
transliteration of ß to ss
>
> I think I'd prefer for this to be added to the conditial too, for
clarity and consistency, to keep the replacements relevant to German
locales in a single place.
But you already have "ß" in the general part - where it's transliterated
to "s". However this is wrong - "ß" is always transliterated to "ss". I
wasn't able to find ANY reliable sources, that transliterated "ß" => "s",
like WP core does.
> >
> > 3) add a 2nd arg to the function remove_accents: $locale = false
(@param string $locale optionally set a locale if you do not want to use
the locale of the current language)
>
> I think this can already be achieved by using `switch_to_locale()` and
`restore_previous_locale()`:
> {{{
> $switched_locale = switch_to_locale( '...' );
>
> $string = remove_accents( $string );
>
> if ( $switched_locale ) {
> restore_previous_locale();
> }
> }}}
>
> The same approach is used when sending emails in user's language instead
of site language, without the need for passing any additional parameters
to the functions.
Good point, I should have mentioned before (since I was aware of this):
Calling switch_to_locale will load all strings of that locale - this has a
major impact on performance and memory-consumption (up to the point of OOM
errors, which can be quickly reached if we have a website that serves
multiple European markets/languages).
For the given use case of "remove_accents" this is breaking a fly on the
wheel (which WP is struggling with in loads of other areas already, don't
want to make it even worse)
I think adding an optional $locale parameter would be a non-invasive
change, that would not impact performance and not break anything either.
Additionally it would make any user directly aware, that remove_accents is
a locale aware function, where locale decides what "result" you get.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54415#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list