Ticket #10971: l10n-translation-noop-performance-2.patch
File l10n-translation-noop-performance-2.patch, 2.8 KB (added by , 15 years ago) |
---|
-
wp-includes/l10n.php
55 55 * @return string Translated text 56 56 */ 57 57 function 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 $translation = isset($l10n[$domain]) ? $l10n[$domain]->translate($text) : $text; 61 return apply_filters('gettext', $translation, $text, $domain); 60 62 } 61 63 62 64 function before_last_bar( $string ) { … … 84 86 } 85 87 86 88 function 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); 89 global $l10n; 90 91 $translation = isset($l10n[$domain]) ? $l10n[$domain]->translate($text, $context) : $text; 92 return apply_filters('gettext_with_context', $translation, $text, $context, $domain); 89 93 } 90 94 91 95 /** … … 236 240 * @return string Either $single or $plural translated text 237 241 */ 238 242 function _n($single, $plural, $number, $domain = 'default') { 239 $translations = &get_translations_for_domain( $domain ); 240 $translation = $translations->translate_plural( $single, $plural, $number ); 243 global $l10n; 244 245 if ( isset($l10n[$domain]) ) 246 $translation = $l10n[$domain]->translate_plural( $single, $plural, $number ); 247 else 248 $translation = 1 == $number ? $single : $plural; 249 241 250 return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); 242 251 } 243 252 … … 251 260 } 252 261 253 262 function _nx($single, $plural, $number, $context, $domain = 'default') { 254 $translations = &get_translations_for_domain( $domain ); 255 $translation = $translations->translate_plural( $single, $plural, $number, $context ); 263 global $l10n; 264 265 if ( isset($l10n[$domain]) ) 266 $translation = $l10n[$domain]->translate_plural( $single, $plural, $number, $context ); 267 else 268 $translation = 1 == $number ? $single : $plural; 269 256 270 return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); 257 271 } 258 272 … … 396 410 } 397 411 398 412 /** 399 * Returns the Translations instance for a domain. If there isn't one,400 * returns empty Translations instance.401 *402 * @param string $domain403 * @return object A Translation instance404 */405 function &get_translations_for_domain( $domain ) {406 global $l10n;407 $empty = &new Translations;408 if ( isset($l10n[$domain]) )409 return $l10n[$domain];410 else411 return $empty;412 }413 414 /**415 413 * Translates role name. Since the role names are in the database and 416 414 * not in the source there are dummy gettext calls to get them into the POT 417 415 * file and this function properly translates them back.