WordPress.org

Make WordPress Core

Ticket #10971: l10n-translation-noop-performance.patch

File l10n-translation-noop-performance.patch, 2.9 KB (added by johanee, 12 years ago)

Make not translating text much, much faster

  • wp-includes/l10n.php

     
    5555 * @return string Translated text
    5656 */
    5757function translate( $text, $domain = 'default' ) {
    58         $translations = &get_translations_for_domain( $domain );
    59         return apply_filters('gettext', $translations->translate($text), $text, $domain);
     58        global $l10n;
     59
     60        if (isset($l10n[$domain]))
     61                return apply_filters('gettext', $l10n[$domain]->translate($text), $text, $domain);
     62        else
     63                return apply_filters('gettext', $text, $text, $domain);
    6064}
    6165
    6266function before_last_bar( $string ) {
     
    8488}
    8589
    8690function translate_with_gettext_context( $text, $context, $domain = 'default' ) {
    87         $translations = &get_translations_for_domain( $domain );
    88         return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain);
     91        global $l10n;
     92
     93        if (isset($l10n[$domain]))
     94                return apply_filters('gettext_with_context', $l10n[$domain]->translate($text, $context), $text, $context, $domain);
     95        else
     96                return apply_filters('gettext_with_context', $text, $text, $context, $domain);
    8997}
    9098
    9199/**
     
    236244 * @return string Either $single or $plural translated text
    237245 */
    238246function _n($single, $plural, $number, $domain = 'default') {
    239         $translations = &get_translations_for_domain( $domain );
    240         $translation = $translations->translate_plural( $single, $plural, $number );
     247        global $l10n;
     248
     249        if ( isset($l10n[$domain]) )
     250                $translation = $l10n[$domain]->translate_plural( $single, $plural, $number );
     251        else
     252                $translation = 1 == $number ? $single : $plural;
     253
    241254        return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
    242255}
    243256
     
    251264}
    252265
    253266function _nx($single, $plural, $number, $context, $domain = 'default') {
    254         $translations = &get_translations_for_domain( $domain );
    255         $translation = $translations->translate_plural( $single, $plural, $number, $context );
     267        global $l10n;
     268
     269        if ( isset($l10n[$domain]) )
     270                $translation = $l10n[$domain]->translate_plural( $single, $plural, $number, $context );
     271        else
     272                $translation = 1 == $number ? $single : $plural;
     273
    256274        return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
    257275}
    258276
     
    396414}
    397415
    398416/**
    399  * Returns the Translations instance for a domain. If there isn't one,
    400  * returns empty Translations instance.
    401  *
    402  * @param string $domain
    403  * @return object A Translation instance
    404  */
    405 function &get_translations_for_domain( $domain ) {
    406         global $l10n;
    407         $empty = &new Translations;
    408         if ( isset($l10n[$domain]) )
    409                 return $l10n[$domain];
    410         else
    411                 return $empty;
    412 }
    413 
    414 /**
    415417 * Translates role name. Since the role names are in the database and
    416418 * not in the source there are dummy gettext calls to get them into the POT
    417419 * file and this function properly translates them back.