Ticket #11012: load_textdomain-hook.diff
| File load_textdomain-hook.diff, 4.6 KB (added by nbachiyski, 2 years ago) |
|---|
-
wp-includes/l10n.php
28 28 function get_locale() { 29 29 global $locale; 30 30 31 if ( isset($locale))31 if ( isset( $locale ) ) 32 32 return apply_filters( 'locale', $locale ); 33 33 34 34 // WPLANG is defined in wp-config. 35 if ( defined('WPLANG'))35 if ( defined( 'WPLANG' ) ) 36 36 $locale = WPLANG; 37 37 38 if ( empty($locale))38 if ( empty( $locale ) ) 39 39 $locale = 'en_US'; 40 40 41 return apply_filters( 'locale', $locale);41 return apply_filters( 'locale', $locale ); 42 42 } 43 43 44 44 /** … … 56 56 */ 57 57 function translate( $text, $domain = 'default' ) { 58 58 $translations = &get_translations_for_domain( $domain ); 59 return apply_filters( 'gettext', $translations->translate($text), $text, $domain);59 return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain ); 60 60 } 61 61 62 62 function before_last_bar( $string ) { … … 80 80 */ 81 81 function translate_with_context( $text, $domain = 'default' ) { 82 82 return before_last_bar( translate( $text, $domain ) ); 83 84 83 } 85 84 86 85 function translate_with_gettext_context( $text, $context, $domain = 'default' ) { 87 86 $translations = &get_translations_for_domain( $domain ); 88 return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain );87 return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); 89 88 } 90 89 91 90 /** … … 195 194 * @param string $domain Optional. Domain to retrieve the translated text 196 195 * @return string Translated context string without pipe 197 196 */ 198 function _c( $text, $domain = 'default') {199 return translate_with_context( $text, $domain);197 function _c( $text, $domain = 'default' ) { 198 return translate_with_context( $text, $domain ); 200 199 } 201 200 202 201 function _x( $single, $context, $domain = 'default' ) { … … 235 234 * @param string $domain Optional. The domain identifier the text should be retrieved in 236 235 * @return string Either $single or $plural translated text 237 236 */ 238 function _n( $single, $plural, $number, $domain = 'default') {237 function _n( $single, $plural, $number, $domain = 'default' ) { 239 238 $translations = &get_translations_for_domain( $domain ); 240 239 $translation = $translations->translate_plural( $single, $plural, $number ); 241 240 return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); … … 316 315 * @param string $mofile Path to the .mo file 317 316 * @return bool true on success, false on failure 318 317 */ 319 function load_textdomain( $domain, $mofile) {318 function load_textdomain( $domain, $mofile ) { 320 319 global $l10n; 320 321 $plugin_override = apply_filters( 'load_textdomain', $domain, $mofile ); 322 323 if ( 'already-loaded' == $plugin_override ) { 324 return true; 325 } 326 327 $mofile = apply_filters( 'load_textdomain_mofile', $mofile ); 321 328 322 329 if ( !is_readable( $mofile ) ) return false; 323 330 … … 344 351 345 352 $mofile = WP_LANG_DIR . "/$locale.mo"; 346 353 347 return load_textdomain( 'default', $mofile);354 return load_textdomain( 'default', $mofile ); 348 355 } 349 356 350 357 /** … … 360 367 * where the .mo file resides. Deprecated, but still functional until 2.7 361 368 * @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR. This is the preferred argument to use. It takes precendence over $abs_rel_path 362 369 */ 363 function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false) {370 function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false ) { 364 371 $locale = get_locale(); 365 372 366 373 if ( false !== $plugin_rel_path ) 367 $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );368 else if ( false !== $abs_rel_path )369 $path = ABSPATH . trim( $abs_rel_path, '/' );374 $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' ); 375 else if ( false !== $abs_rel_path ) 376 $path = ABSPATH . trim( $abs_rel_path, '/' ); 370 377 else 371 378 $path = WP_PLUGIN_DIR; 372 379 373 380 $mofile = $path . '/'. $domain . '-' . $locale . '.mo'; 374 return load_textdomain( $domain, $mofile);381 return load_textdomain( $domain, $mofile ); 375 382 } 376 383 377 384 /** … … 404 411 */ 405 412 function &get_translations_for_domain( $domain ) { 406 413 global $l10n; 407 if ( !isset( $l10n[$domain]) ) {414 if ( !isset( $l10n[$domain] ) ) { 408 415 $l10n[$domain] = &new NOOP_Translations; 409 416 } 410 417 return $l10n[$domain]; … … 421 428 * won't suffer from that problem. 422 429 */ 423 430 function translate_user_role( $name ) { 424 return translate_with_gettext_context( before_last_bar( $name), 'User role' );425 } 426 ?> 431 return translate_with_gettext_context( before_last_bar( $name ), 'User role' ); 432 } 433 No newline at end of file
