Ticket #10971: l10n-translation-empty-class.patch

File l10n-translation-empty-class.patch, 1.2 KB (added by johanee, 4 years ago)

Use minimal Empty_Translation object when none available

  • wp-includes/l10n.php

     
    396396} 
    397397 
    398398/** 
     399 * Empty translation class used when no Translation object is available 
     400 * for domain. 
     401 * 
     402 * @package WordPress 
     403 * @since 2.9.0 
     404 */ 
     405Class Empty_Translation { 
     406        function translate($text, $context = '') { 
     407                return $text; 
     408        } 
     409 
     410        function translate_plural($single, $plural, $number) { 
     411                return $number == 1 ? $single : $plural; 
     412        } 
     413} 
     414 
     415/** 
    399416 * Returns the Translations instance for a domain. If there isn't one, 
    400  * returns empty Translations instance. 
     417 * returns Empty_Translations instance. That means the only valid methods 
     418 * are translate() and translate_plural(). 
    401419 * 
    402420 * @param string $domain 
    403  * @return object A Translation instance 
     421 * @return object An (Empty_)Translation instance 
    404422 */ 
    405423function &get_translations_for_domain( $domain ) { 
    406424        global $l10n; 
    407         $empty = &new Translations; 
     425        static $empty; 
     426 
    408427        if ( isset($l10n[$domain]) ) 
    409428                return $l10n[$domain]; 
    410         else 
     429        else { 
     430                if (!isset($empty)) 
     431                        $empty = &new Empty_Translation(); 
    411432                return $empty; 
     433        } 
    412434} 
    413435 
    414436/**