Ticket #32380: fix_wptexturize_locale_switch.2.patch
File fix_wptexturize_locale_switch.2.patch, 3.6 KB (added by , 10 years ago) |
---|
-
tests/phpunit/tests/formatting/WPTexturize.php
From 3e18341c5c4eda7674579ee54bb678b20ff687ab Mon Sep 17 00:00:00 2001 From: Ivan Blagdan <ivan.blagdan@gmail.com> Date: Wed, 13 May 2015 20:39:07 +0200 Subject: [PATCH 1/2] test if wptexturize is switching locale properly --- tests/phpunit/tests/formatting/WPTexturize.php | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 0eb08e2..001e86e 100644
a b class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 1849 1849 ), 1850 1850 ); 1851 1851 } 1852 1853 /** 1854 * Test proper wptexturize behaviour between two switched locales 1855 */ 1856 function test_locale_change_handling() { 1857 $input = '""'; // Testing against a pair of quotes for wptexturize to handle. 1858 wptexturize( $input ); // 1 fake run 1859 1860 // Switch to a different locale; 1861 add_filter( 'locale', create_function('$lang', 'return "fr_FR";' ), 10, 1 ); 1862 // Hook to a gettext call to simulate a switch to .PO localized with guillemets 1863 add_filter( 'gettext_with_context', array($this, '_filter_curly_double_quotes'), 10, 4 ); 1864 1865 // Poper entities are translated via a gettext call 1866 $opening_quote = _x( '“', 'opening curly double quote' ); 1867 $closing_quote = _x( '”', 'closing curly double quote' ); 1868 1869 return $this->assertEquals( $opening_quote . $closing_quote, wptexturize( $input ) ); 1870 } 1871 1872 /** 1873 * Switch smart quote style via gettext. 1874 */ 1875 function _filter_curly_double_quotes( $translations, $text, $context, $domain ) { 1876 if ( 'opening curly double quote' == $context && '“' == $text ) { 1877 $translations = '«'; 1878 } else if ( 'closing curly double quote' == $context && '”' == $text ) { 1879 $translations = '»'; 1880 } 1881 1882 return $translations; 1883 } 1852 1884 } 1885 No newline at end of file -
src/wp-includes/formatting.php
-- 2.3.2 (Apple Git-55) From de4b711f93b8542bf8aa1cc260f8d5576b1d4a8a Mon Sep 17 00:00:00 2001 From: Ivan Blagdan <ivan.blagdan@gmail.com> Date: Wed, 13 May 2015 20:40:45 +0200 Subject: [PATCH 2/2] fix wptexturize to reset if the locale changed --- src/wp-includes/formatting.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index eacc260..94a702d 100644
a b 30 30 function wptexturize($text, $reset = false) { 31 31 global $wp_cockneyreplace, $shortcode_tags; 32 32 static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, 33 $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true ;33 $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true, $locale; 34 34 35 35 // If there's nothing to do, just stop. 36 36 if ( empty( $text ) || false === $run_texturize ) { 37 37 return $text; 38 38 } 39 39 40 // Set up static variables. Run once only .41 if ( $reset || ! isset( $static_characters ) ) {40 // Set up static variables. Run once only, unless the locale has been changed. 41 if ( $reset || ! isset( $static_characters ) || $locale != get_locale() ) { 42 42 /** 43 43 * Filter whether to skip running wptexturize(). 44 44 * … … function wptexturize($text, $reset = false) { 58 58 return $text; 59 59 } 60 60 61 // Get the current locale and store it on the first run. 62 $locale = get_locale(); 63 61 64 /* translators: opening curly double quote */ 62 65 $opening_quote = _x( '“', 'opening curly double quote' ); 63 66 /* translators: closing curly double quote */