Make WordPress Core


Ignore:
Timestamp:
02/28/2022 03:40:15 PM (2 years ago)
Author:
SergeyBiryukov
Message:

I18N: Add a $locale parameter for remove_accents().

This highlights the fact that remove_accents() is locale-aware and makes it easier to utilize the function with different locales without having to use switch_to_locale() or the locale filter.

Additionally, this commit relaxes the check for character replacements in German locales to include formal and informal variants of any de_* locale, even if WordPress does not have a native translation for some of them yet.

Props malthert, johnbillion, knutsp, ocean90, SergeyBiryukov.
Fixes #54415.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/removeAccents.php

    r52010 r52809  
    8181    }
    8282
    83     public function remove_accents_germanic_umlauts_cb() {
    84         return 'de_DE';
    85     }
    86 
    8783    /**
    8884     * @ticket 3782
    8985     */
    9086    public function test_remove_accents_germanic_umlauts() {
    91         add_filter( 'locale', array( $this, 'remove_accents_germanic_umlauts_cb' ) );
    92 
    93         $this->assertSame( 'AeOeUeaeoeuess', remove_accents( 'ÄÖÜäöüß' ) );
    94 
    95         remove_filter( 'locale', array( $this, 'remove_accents_germanic_umlauts_cb' ) );
    96     }
    97 
    98     public function set_locale_to_danish() {
    99         return 'da_DK';
     87        $this->assertSame( 'AeOeUeaeoeuess', remove_accents( 'ÄÖÜäöüß', 'de_DE' ) );
    10088    }
    10189
     
    10492     */
    10593    public function test_remove_danish_accents() {
    106         add_filter( 'locale', array( $this, 'set_locale_to_danish' ) );
    107 
    108         $this->assertSame( 'AeOeAaaeoeaa', remove_accents( 'ÆØÅæøå' ) );
    109 
    110         remove_filter( 'locale', array( $this, 'set_locale_to_danish' ) );
    111     }
    112 
    113     public function set_locale_to_catalan() {
    114         return 'ca';
     94        $this->assertSame( 'AeOeAaaeoeaa', remove_accents( 'ÆØÅæøå', 'da_DK' ) );
    11595    }
    11696
     
    11999     */
    120100    public function test_remove_catalan_middot() {
    121         add_filter( 'locale', array( $this, 'set_locale_to_catalan' ) );
    122 
    123         $this->assertSame( 'allallalla', remove_accents( 'al·lallaŀla' ) );
    124 
    125         remove_filter( 'locale', array( $this, 'set_locale_to_catalan' ) );
    126 
     101        $this->assertSame( 'allallalla', remove_accents( 'al·lallaŀla', 'ca' ) );
    127102        $this->assertSame( 'al·lallalla', remove_accents( 'al·lallaŀla' ) );
    128     }
    129 
    130     public function set_locale_to_serbian() {
    131         return 'sr_RS';
    132103    }
    133104
     
    136107     */
    137108    public function test_transcribe_serbian_crossed_d() {
    138         add_filter( 'locale', array( $this, 'set_locale_to_serbian' ) );
    139 
    140         $this->assertSame( 'DJdj', remove_accents( 'Đđ' ) );
    141 
    142         remove_filter( 'locale', array( $this, 'set_locale_to_serbian' ) );
    143 
     109        $this->assertSame( 'DJdj', remove_accents( 'Đđ', 'sr_RS' ) );
    144110        $this->assertSame( 'Dd', remove_accents( 'Đđ' ) );
    145111    }
Note: See TracChangeset for help on using the changeset viewer.