Changeset 52809
- Timestamp:
- 02/28/2022 03:40:15 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r52789 r52809 1584 1584 * @since 4.8.0 Added locale support for `bs_BA`. 1585 1585 * @since 5.7.0 Added locale support for `de_AT`. 1586 * 1587 * @param string $string Text that might have accent characters 1586 * @since 6.0.0 Added the `$locale` parameter. 1587 * 1588 * @param string $string Text that might have accent characters. 1589 * @param string $locale Optional. The locale to use for accent removal. Some character 1590 * replacements depend on the locale being used (e.g. 'de_DE'). 1591 * Defaults to the current locale. 1588 1592 * @return string Filtered string with replaced "nice" characters. 1589 1593 */ 1590 function remove_accents( $string ) {1594 function remove_accents( $string, $locale = '' ) { 1591 1595 if ( ! preg_match( '/[\x80-\xff]/', $string ) ) { 1592 1596 return $string; … … 1924 1928 1925 1929 // Used for locale-specific rules. 1926 $locale = get_locale(); 1927 1928 if ( in_array( $locale, array( 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal', 'de_AT' ), true ) ) { 1930 if ( empty( $locale ) ) { 1931 $locale = get_locale(); 1932 } 1933 1934 /* 1935 * German has various locales (de_DE, de_CH, de_AT, ...) with formal and informal variants. 1936 * There is no 3-letter locale like 'def', so checking for 'de' instead of 'de_' is safe, 1937 * since 'de' itself would be a valid locale too). 1938 */ 1939 if ( str_starts_with( $locale, 'de' ) ) { 1929 1940 $chars['Ä'] = 'Ae'; 1930 1941 $chars['ä'] = 'ae'; -
trunk/tests/phpunit/tests/formatting/removeAccents.php
r52010 r52809 81 81 } 82 82 83 public function remove_accents_germanic_umlauts_cb() {84 return 'de_DE';85 }86 87 83 /** 88 84 * @ticket 3782 89 85 */ 90 86 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' ) ); 100 88 } 101 89 … … 104 92 */ 105 93 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' ) ); 115 95 } 116 96 … … 119 99 */ 120 100 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' ) ); 127 102 $this->assertSame( 'al·lallalla', remove_accents( 'al·lallaŀla' ) ); 128 }129 130 public function set_locale_to_serbian() {131 return 'sr_RS';132 103 } 133 104 … … 136 107 */ 137 108 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' ) ); 144 110 $this->assertSame( 'Dd', remove_accents( 'Đđ' ) ); 145 111 }
Note: See TracChangeset
for help on using the changeset viewer.