WordPress.org

Make WordPress Core

Changeset 19795


Ignore:
Timestamp:
01/31/12 14:06:32 (3 years ago)
Author:
nacin
Message:

Allow the single quotes, apostrophes, and primes in wptexturize() to be translated. Allows replacements to be disabled by translating them back to " and '. fixes #19602.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r19712 r19795  
    2929function wptexturize($text) { 
    3030    global $wp_cockneyreplace; 
    31     static $opening_quote, $closing_quote, $en_dash, $em_dash, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements; 
     31    static $opening_quote, $closing_quote, $opening_single_quote, $closing_single_quote, $en_dash, $em_dash, 
     32        $apos, $prime, $double_prime, $default_no_texturize_tags, $default_no_texturize_shortcodes, 
     33        $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements; 
    3234 
    3335    // No need to set up these static variables more than once 
    3436    if ( empty( $opening_quote ) ) { 
    35         /* translators: opening curly quote */ 
    36         $opening_quote = _x('“', 'opening curly quote'); 
    37         /* translators: closing curly quote */ 
    38         $closing_quote = _x('”', 'closing curly quote'); 
     37        /* translators: opening curly double quote */ 
     38        $opening_quote = _x( '“', 'opening curly double quote' ); 
     39        /* translators: closing curly double quote */ 
     40        $closing_quote = _x( '”', 'closing curly double quote' ); 
     41 
     42        /* translators: apostrophe, for example in 'cause or can't */ 
     43        $apos = _x( '’', 'apostrophe' ); 
     44 
     45        /* translators: prime, for example in 9' (nine feet) */ 
     46        $prime = _x( '′', 'prime' ); 
     47        /* translators: double prime, for example in 9" (nine inches) */ 
     48        $double_prime = _x( '″', 'double prime' ); 
     49 
     50        /* translators: opening curly single quote */ 
     51        $opening_single_quote = _x( '‘', 'opening curly single quote' ); 
     52        /* translators: closing curly single quote */ 
     53        $closing_single_quote = _x( '’', 'closing curly single quote' ); 
     54 
    3955        /* translators: en dash */ 
    40         $en_dash = _x('–', 'en dash'); 
     56        $en_dash = _x( '–', 'en dash' ); 
    4157        /* translators: em dash */ 
    42         $em_dash = _x('—', 'em dash'); 
     58        $em_dash = _x( '—', 'em dash' ); 
    4359 
    4460        $default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt'); 
     
    4965            $cockney = array_keys($wp_cockneyreplace); 
    5066            $cockneyreplace = array_values($wp_cockneyreplace); 
     67        } elseif ( "'" != $apos ) { // Only bother if we're doing a replacement. 
     68            $cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause" ); 
     69            $cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause" ); 
    5170        } else { 
    52             $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause"); 
    53             $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause"); 
     71            $cockney = $cockneyreplace = array(); 
    5472        } 
    5573 
    56         $static_characters = array_merge( array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney ); 
    57         $static_replacements = array_merge( array($em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace ); 
    58  
    59         $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/'); 
    60         $dynamic_replacements = array('&#8217;$1','&#8217;$1', '$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '&#8217;$1', '$1&#215;$2'); 
     74        $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn&#8211;', '...', '``', '\'\'', ' (tm)' ), $cockney ); 
     75        $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '&#8230;', $opening_quote, $closing_quote, ' &#8482;' ), $cockneyreplace ); 
     76 
     77        $dynamic = array(); 
     78        if ( "'" != $apos ) { 
     79            $dynamic[ '/\'(\d\d(?:&#8217;|\')?s)/' ] = $apos . '$1'; // '99's 
     80            $dynamic[ '/\'(\d)/'                   ] = $apos . '$1'; // '99 
     81        } 
     82        if ( "'" != $opening_single_quote ) 
     83            $dynamic[ '/(\s|\A|[([{<]|")\'/'       ] = '$1' . $opening_single_quote; // opening single quote, even after (, {, <, [ 
     84        if ( '"' != $double_prime ) 
     85            $dynamic[ '/(\d)"/'                    ] = '$1' . $double_prime; // 9" (double prime) 
     86        if ( "'" != $prime ) 
     87            $dynamic[ '/(\d)\'/'                   ] = '$1' . $prime; // 9' (prime) 
     88        if ( "'" != $apos ) 
     89            $dynamic[ '/(\S)\'([^\'\s])/'          ] = '$1' . $apos . '$2'; // apostrophe in a word 
     90        if ( '"' != $opening_quote ) 
     91            $dynamic[ '/(\s|\A|[([{<])"(?!\s)/'    ] = '$1' . $opening_quote . '$2'; // opening double quote, even after (, {, <, [ 
     92        if ( '"' != $closing_quote ) 
     93            $dynamic[ '/"(\s|\S|\Z)/'              ] = $closing_quote . '$1'; // closing double quote 
     94        if ( "'" != $closing_single_quote ) 
     95            $dynamic[ '/\'([\s.]|\Z)/'             ] = $closing_single_quote . '$2'; // closing single quote 
     96 
     97        $dynamic[ '/\b(\d+)x(\d+)\b/'              ] = '$1&#215;$2'; // 9x9 (times) 
     98 
     99        $dynamic_characters = array_keys( $dynamic ); 
     100        $dynamic_replacements = array_values( $dynamic ); 
    61101    } 
    62102 
Note: See TracChangeset for help on using the changeset viewer.