WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 21 months ago

#45592 closed enhancement (worksforme)

Remove Accents

Reported by: MaximeCulea Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.0
Component: Formatting Keywords:
Focuses: Cc:

Description

I have been lately working on an extension for library filename sanitization and seen this on wp-includes/formatting.php :

<?php
// Used for locale-specific rules
$locale = get_locale();
if ( 'de_DE' == $locale || 'de_DE_formal' == $locale || 'de_CH' == $locale || 'de_CH_informal' == $locale ) {
        $chars['Ä'] = 'Ae';
        $chars['ä'] = 'ae';
        $chars['Ö'] = 'Oe';
        $chars['ö'] = 'oe';
        $chars['Ü'] = 'Ue';
        $chars['ü'] = 'ue';
        $chars['ß'] = 'ss';
} elseif ( 'da_DK' === $locale ) {
        $chars['Æ'] = 'Ae';
        $chars['æ'] = 'ae';
        $chars['Ø'] = 'Oe';
        $chars['ø'] = 'oe';
        $chars['Å'] = 'Aa';
        $chars['å'] = 'aa';
} elseif ( 'ca' === $locale ) {
        $chars['l·l'] = 'll';
} elseif ( 'sr_RS' === $locale || 'bs_BA' === $locale ) {
        $chars['Đ'] = 'DJ';
        $chars['đ'] = 'dj';
}

What is the purpose about applying theses replacements only for certains languages ?

Moreover, why base this on the locale and not the user locale ?

Change History (4)

#1 @swissspidy
2 years ago

Why base this on the locale and not the user locale ?

remove_accents() is used to remove accents from usernames and permalink slugs. These things are dependant on the site locale, not the user locale.

#2 follow-up: @MaximeCulea
2 years ago

Seems legit @swissspidy, thx.

But why doing "replacements" only for certains languages ?
If my site is french and I upload an image with a filename with a "ß", I would expect to be replaced, isn't it ?

#3 in reply to: ↑ 2 @SergeyBiryukov
2 years ago

  • Keywords close added

Replying to MaximeCulea:

But why doing "replacements" only for certains languages ?

Above the code you've quoted, there's a longer list of replacements that apply to all locales. Some locales, however, transliterate some characters differently. See #3782, #23907, #37086, #38078 for details. As noted in the comment, these are locale-specific replacements.

If my site is french and I upload an image with a filename with a "ß", I would expect to be replaced, isn't it ?

It will be replaced with 's', as per 'ß' => 's' in line 1550.

#4 @desrosj
21 months ago

  • Keywords 2nd-opinion close removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from assigned to closed

Closing this one out as it seems to be working as expected.

Note: See TracTickets for help on using tickets.