Ticket #16750: 16750.diff
| File 16750.diff, 24.0 KB (added by , 13 years ago) |
|---|
-
src/wp-includes/l10n.php
7 7 */ 8 8 9 9 /** 10 * Get sthe current locale.10 * Get the current locale. 11 11 * 12 12 * If the locale is set, then it will filter the locale in the 'locale' filter 13 13 * hook and return the value. … … 20 20 * always be filtered using the 'locale' hook. 21 21 * 22 22 * @since 1.5.0 23 * @uses apply_filters() Calls 'locale' hook on locale value.24 * @uses $locale Gets the locale stored in the global.25 23 * 26 24 * @return string The locale of the blog or from the 'locale' hook. 27 25 */ … … 52 50 } 53 51 54 52 /** 55 * Retrieves the translation of $text. If there is no translation, or 56 * the domain isn't loaded, the original text is returned. 53 * Retrieve the translation of $text. 57 54 * 58 * @see __() Don't use translate() directly, use __() 55 * If there is no translation, or the domain isn't loaded, the original text is returned. 56 * 57 * <strong>Note:</strong> Don't use translate() directly, use __() or related functions. 58 * 59 59 * @since 2.2.0 60 * @uses apply_filters() Calls 'gettext' on domain translated text61 * with the untranslated text as second parameter.62 60 * 63 * @param string $text Text to translate.64 * @param string $domain Domain to retrieve the translated text.61 * @param string $text Text to translate. 62 * @param string $domain (optional) Unique identifier for retrieving translated strings. 65 63 * @return string Translated text 66 64 */ 67 65 function translate( $text, $domain = 'default' ) { … … 69 67 return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain ); 70 68 } 71 69 70 /** 71 * Remove last item on a pipe-delimited string. 72 * 73 * Meant for removing the last item in a string, such as 'Role name|User role'. The original 74 * string will be returned if no pipe '|' characters are found in the string. 75 * 76 * @since 2.8.0 77 * 78 * @param string $string A pipe-delimited string. 79 * @return string Either $string or everything before the last pipe. 80 */ 72 81 function before_last_bar( $string ) { 73 82 $last_bar = strrpos( $string, '|' ); 74 83 if ( false == $last_bar ) … … 77 86 return substr( $string, 0, $last_bar ); 78 87 } 79 88 89 /** 90 * Retrieve the translation of $text in the context defined in $context. 91 * 92 * If there is no translation, or the domain isn't loaded the original 93 * text is returned. 94 * 95 * @since 2.8.0 96 * 97 * @param string $text Text to translate. 98 * @param string $context Context information for the translators. 99 * @param string $domain (optional) Unique identifier for retrieving translated strings. 100 * @return string Translated text on success, original text on failure. 101 */ 80 102 function translate_with_gettext_context( $text, $context, $domain = 'default' ) { 81 103 $translations = get_translations_for_domain( $domain ); 82 104 return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); 83 105 } 84 106 85 107 /** 86 * Retrieve s the translation of $text. If there is no translation, or87 * the domain isn't loaded, the original text is returned.108 * Retrieve the translation of $text. If there is no translation, 109 * or the domain isn't loaded, the original text is returned. 88 110 * 89 * @see translate() An alias of translate()90 111 * @since 2.1.0 91 112 * 92 * @param string $text Text to translate93 * @param string $domain Optional. Domain to retrieve the translated text94 * @return string Translated text 113 * @param string $text Text to translate. 114 * @param string $domain (optional) Unique identifier for retrieving translated strings. 115 * @return string Translated text. 95 116 */ 96 117 function __( $text, $domain = 'default' ) { 97 118 return translate( $text, $domain ); 98 119 } 99 120 100 121 /** 101 * Retrieves the translation of $text and escapes it for safe use in an attribute. 122 * Retrieve the translation of $text and escapes it for safe use in an attribute. 123 * 102 124 * If there is no translation, or the domain isn't loaded, the original text is returned. 103 125 * 104 * @see translate() An alias of translate()105 * @see esc_attr()106 126 * @since 2.8.0 107 127 * 108 * @param string $text Text to translate109 * @param string $domain Optional. Domain to retrieve the translated text110 * @return string Translated text 128 * @param string $text Text to translate. 129 * @param string $domain (optional) Unique identifier for retrieving translated strings. 130 * @return string Translated text on success, original text on failure. 111 131 */ 112 132 function esc_attr__( $text, $domain = 'default' ) { 113 133 return esc_attr( translate( $text, $domain ) ); 114 134 } 115 135 116 136 /** 117 * Retrieves the translation of $text and escapes it for safe use in HTML output. 137 * Retrieve the translation of $text and escapes it for safe use in HTML output. 138 * 118 139 * If there is no translation, or the domain isn't loaded, the original text is returned. 119 140 * 120 * @see translate() An alias of translate()121 * @see esc_html()122 141 * @since 2.8.0 123 142 * 124 * @param string $text Text to translate125 * @param string $domain Optional. Domain to retrieve the translated text143 * @param string $text Text to translate. 144 * @param string $domain (optional) Unique identifier for retrieving translated strings. 126 145 * @return string Translated text 127 146 */ 128 147 function esc_html__( $text, $domain = 'default' ) { … … 130 149 } 131 150 132 151 /** 133 * Display s the returned translated text from translate().152 * Display translated text. 134 153 * 135 * @see translate() Echoes returned translate() string136 154 * @since 1.2.0 137 155 * 138 * @param string $text Text to translate139 * @param string $domain Optional. Domain to retrieve the translated text156 * @param string $text Text to translate. 157 * @param string $domain (optional) Unique identifier for retrieving translated strings. 140 158 */ 141 159 function _e( $text, $domain = 'default' ) { 142 160 echo translate( $text, $domain ); 143 161 } 144 162 145 163 /** 146 * Display stranslated text that has been escaped for safe use in an attribute.164 * Display translated text that has been escaped for safe use in an attribute. 147 165 * 148 * @see translate() Echoes returned translate() string149 * @see esc_attr()150 166 * @since 2.8.0 151 167 * 152 * @param string $text Text to translate153 * @param string $domain Optional. Domain to retrieve the translated text168 * @param string $text Text to translate. 169 * @param string $domain (optional) Unique identifier for retrieving translated strings. 154 170 */ 155 171 function esc_attr_e( $text, $domain = 'default' ) { 156 172 echo esc_attr( translate( $text, $domain ) ); 157 173 } 158 174 159 175 /** 160 * Display stranslated text that has been escaped for safe use in HTML output.176 * Display translated text that has been escaped for safe use in HTML output. 161 177 * 162 * @see translate() Echoes returned translate() string163 * @see esc_html()164 178 * @since 2.8.0 165 179 * 166 * @param string $text Text to translate167 * @param string $domain Optional. Domain to retrieve the translated text180 * @param string $text Text to translate. 181 * @param string $domain (optional) Unique identifier for retrieving translated strings. 168 182 */ 169 183 function esc_html_e( $text, $domain = 'default' ) { 170 184 echo esc_html( translate( $text, $domain ) ); 171 185 } 172 186 173 187 /** 174 * Retrieve translated string with gettext context 188 * Retrieve translated string with gettext context. 175 189 * 176 190 * Quite a few times, there will be collisions with similar translatable text 177 * found in more than two places but with different translated context.191 * found in more than two places, but with different translated context. 178 192 * 179 * By including the context in the pot file translators can translate the two193 * By including the context in the pot file, translators can translate the two 180 194 * strings differently. 181 195 * 182 196 * @since 2.8.0 183 197 * 184 * @param string $text Text to translate185 * @param string $context Context information for the translators 186 * @param string $domain Optional. Domain to retrieve the translated text187 * @return string Translated context string without pipe 198 * @param string $text Text to translate. 199 * @param string $context Context information for the translators. 200 * @param string $domain (optional) Unique identifier for retrieving translated strings. 201 * @return string Translated context string without pipe. 188 202 */ 189 203 function _x( $text, $context, $domain = 'default' ) { 190 204 return translate_with_gettext_context( $text, $context, $domain ); 191 205 } 192 206 193 207 /** 194 * Display s translated string with gettext context208 * Display translated string with gettext context. 195 209 * 196 * @see _x197 210 * @since 3.0.0 198 211 * 199 * @param string $text Text to translate200 * @param string $context Context information for the translators 201 * @param string $domain Optional. Domain to retrieve the translated text202 * @return string Translated context string without pipe 212 * @param string $text Text to translate. 213 * @param string $context Context information for the translators. 214 * @param string $domain (optional) Unique identifier for retrieving translated strings. 215 * @return string Translated context string without pipe. 203 216 */ 204 217 function _ex( $text, $context, $domain = 'default' ) { 205 218 echo _x( $text, $context, $domain ); 206 219 } 207 220 208 221 /** 209 * Display s translated string with gettext contextand escapes it for safe use in an attribute.222 * Display translated string with gettext context, and escapes it for safe use in an attribute. 210 223 * 211 * @see esc_attr()212 224 * @since 2.8.0 213 225 * 214 * @param string $text Text to translate215 * @param string $context Context information for the translators 216 * @param string $domain Optional. Domain to retrieve the translated text226 * @param string $text Text to translate. 227 * @param string $context Context information for the translators. 228 * @param string $domain (optional) Unique identifier for retrieving translated strings. 217 229 * @return string Translated text 218 230 */ 219 231 function esc_attr_x( $text, $context, $domain = 'default' ) { … … 221 233 } 222 234 223 235 /** 224 * Display s translated string with gettext contextand escapes it for safe use in HTML output.236 * Display translated string with gettext context, and escapes it for safe use in HTML output. 225 237 * 226 * @see esc_html()227 238 * @since 2.9.0 228 239 * 229 * @param string $text Text to translate230 * @param string $context Context information for the translators 231 * @param string $domain Optional. Domain to retrieve the translated text232 * @return string Translated text 240 * @param string $text Text to translate. 241 * @param string $context Context information for the translators. 242 * @param string $domain (optional) Unique identifier for retrieving translated strings. 243 * @return string Translated text. 233 244 */ 234 245 function esc_html_x( $text, $context, $domain = 'default' ) { 235 246 return esc_html( translate_with_gettext_context( $text, $context, $domain ) ); 236 247 } 237 248 238 249 /** 239 * Retrieve the plural or single form based on the amount.250 * Retrieve the plural or single form based on the supplied amount. 240 251 * 241 252 * If the domain is not set in the $l10n list, then a comparison will be made 242 253 * and either $plural or $single parameters returned. … … 247 258 * type will be a string. 248 259 * 249 260 * @since 2.8.0 250 * @uses $l10n Gets list of domain translated string (gettext_reader) objects251 * @uses apply_filters() Calls 'ngettext' hook on domains text returned,252 * along with $single, $plural, and $number parameters. Expected to return string.253 261 * 254 * @param string $single The text that will be used if $number is 1 255 * @param string $plural The text that will be used if $number is not 1 256 * @param int $number The number to compare against to use either $single or $plural257 * @param string $domain Optional. The domain identifier the text should be retrieved in258 * @return string Either $single or $plural translated text 262 * @param string $single The text that will be used if $number is 1. 263 * @param string $plural The text that will be used if $number is not 1. 264 * @param int $number The number to compare against to use either $single or $plural. 265 * @param string $domain (optional) Unique identifier for retrieving translated strings. 266 * @return string Either $single or $plural translated text. 259 267 */ 260 268 function _n( $single, $plural, $number, $domain = 'default' ) { 261 269 $translations = get_translations_for_domain( $domain ); … … 264 272 } 265 273 266 274 /** 267 * A hybrid of _n() and _x(). It supports contexts and plurals.275 * Retrieve the plural or single form based on the supplied amount with gettext context. 268 276 * 269 * @see _n() 270 * @see _x() 277 * This is a hybrid of _n() and _x(). It supports contexts and plurals. 271 278 * 279 * @since 2.8.0 280 * 281 * @param string $single The text that will be used if $number is 1. 282 * @param string $plural The text that will be used if $number is not 1. 283 * @param int $number The number to compare against to use either $single or $plural. 284 * @param string $context Context information for the translators. 285 * @param string $domain (optional) Unique identifier for retrieving translated strings. 286 * @return string Either $single or $plural translated text with context. 272 287 */ 273 288 function _nx($single, $plural, $number, $context, $domain = 'default') { 274 289 $translations = get_translations_for_domain( $domain ); … … 279 294 /** 280 295 * Register plural strings in POT file, but don't translate them. 281 296 * 282 * Used when you want to keep structures with translatable plural strings and283 * use them later.297 * Used when you want to keep structures with translatable plural 298 * strings and use them later. 284 299 * 285 300 * Example: 286 * $messages = array( 301 * <code> 302 * $messages = array( 287 303 * 'post' => _n_noop('%s post', '%s posts'), 288 304 * 'page' => _n_noop('%s pages', '%s pages') 289 * ); 290 * ... 291 * $message = $messages[$type]; 292 * $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count ); 305 * ); 306 * ... 307 * $message = $messages[$type]; 308 * $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count ); 309 * </code> 293 310 * 294 * @since 2.5 295 * @param string $singular Single form to be i18ned 296 * @param string $plural Plural form to be i18ned 297 * @param string $domain Optional. The domain identifier the text will be retrieved in 311 * @since 2.5.0 312 * 313 * @param string $singular Single form to be i18ned. 314 * @param string $plural Plural form to be i18ned. 315 * @param string $domain (optional) Unique identifier for retrieving translated strings. 298 316 * @return array array($singular, $plural) 299 317 */ 300 318 function _n_noop( $singular, $plural, $domain = null ) { … … 304 322 /** 305 323 * Register plural strings with context in POT file, but don't translate them. 306 324 * 307 * @s ee _n_noop()325 * @since 2.8.0 308 326 */ 309 327 function _nx_noop( $singular, $plural, $context, $domain = null ) { 310 328 return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain ); 311 329 } 312 330 313 331 /** 314 * Translate the result of _n_noop() or _nx_noop() 332 * Translate the result of _n_noop() or _nx_noop(). 315 333 * 316 * @since 3.1 317 * @param array $nooped_plural Array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop() 318 * @param int $count Number of objects 319 * @param string $domain Optional. The domain identifier the text should be retrieved in. If $nooped_plural contains 320 * a domain passed to _n_noop() or _nx_noop(), it will override this value. 334 * @since 3.1.0 335 * 336 * @param array $nooped_plural Array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop() 337 * @param int $count Number of objects 338 * @param string $domain (optional) Unique identifier for retrieving translated strings. If $nooped_plural contains 339 * a domain passed to _n_noop() or _nx_noop(), it will override this value. 340 * @return string Either $single or $plural translated text. 321 341 */ 322 342 function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { 323 343 if ( $nooped_plural['domain'] ) … … 330 350 } 331 351 332 352 /** 333 * Load s a MOfile into the domain $domain.353 * Load a .mo file into the domain $domain. 334 354 * 335 355 * If the domain already exists, the translations will be merged. If both 336 356 * sets have the same string, the translation from the original value will be taken. … … 339 359 * and will be a MO object. 340 360 * 341 361 * @since 1.5.0 342 * @uses $l10n Gets list of domain translated string objects343 362 * 344 * @param string $domain Unique identifier for retrieving translated strings 345 * @param string $mofile Path to the .mo file 346 * @return bool True on success, false on failure 363 * @param string $domain Unique identifier for retrieving translated strings. 364 * @param string $mofile Path to the .mo file. 365 * @return bool True on success, false on failure. 347 366 */ 348 367 function load_textdomain( $domain, $mofile ) { 349 368 global $l10n; … … 372 391 } 373 392 374 393 /** 375 * Unload s translations for a domain394 * Unload translations for a domain. 376 395 * 377 396 * @since 3.0.0 378 * @param string $domain Textdomain to be unloaded 379 * @return bool Whether textdomain was unloaded 397 * 398 * @param string $domain Unique identifier for retrieving translated strings. 399 * @return bool Whether textdomain was unloaded. 380 400 */ 381 401 function unload_textdomain( $domain ) { 382 402 global $l10n; … … 397 417 } 398 418 399 419 /** 400 * Load sdefault translated strings based on locale.420 * Load default translated strings based on locale. 401 421 * 402 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. The403 * translated (.mo) file is named based on the locale.422 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. 423 * The translated (.mo) file is named based on the locale. 404 424 * 425 * @see load_textdomain() 426 * 405 427 * @since 1.5.0 406 428 */ 407 429 function load_default_textdomain() { … … 423 445 } 424 446 425 447 /** 426 * Load s theplugin's translated strings.448 * Load a plugin's translated strings. 427 449 * 428 450 * If the path is not given then it will be the root of the plugin directory. 451 * 429 452 * The .mo file should be named based on the domain with a dash, and then the locale exactly. 430 453 * 431 454 * @since 1.5.0 432 455 * 433 * @param string $domain Unique identifier for retrieving translated strings 434 * @param string $abs_rel_path Optional. Relative path to ABSPATH of a folder, 435 * where the .mo file resides. Deprecated, but still functional until 2.7 436 * @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR. This is the preferred argument to use. It takes precedence over $abs_rel_path 456 * @param string $domain Unique identifier for retrieving translated strings 457 * @param string $deprecated Use the $plugin_rel_path parameter instead. 458 * @param string $plugin_rel_path (optional) Relative path to WP_PLUGIN_DIR where the .mo file resides. 437 459 */ 438 function load_plugin_textdomain( $domain, $ abs_rel_path= false, $plugin_rel_path = false ) {460 function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { 439 461 $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); 440 462 441 463 if ( false !== $plugin_rel_path ) { 442 464 $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' ); 443 } else if ( false !== $ abs_rel_path) {465 } else if ( false !== $deprecated ) { 444 466 _deprecated_argument( __FUNCTION__, '2.7' ); 445 $path = ABSPATH . trim( $ abs_rel_path, '/' );467 $path = ABSPATH . trim( $deprecated, '/' ); 446 468 } else { 447 469 $path = WP_PLUGIN_DIR; 448 470 } … … 458 480 } 459 481 460 482 /** 461 * Load the translated strings for a plugin residing in the mu-plugins dir .483 * Load the translated strings for a plugin residing in the mu-plugins directory. 462 484 * 463 485 * @since 3.0.0 464 486 * 465 * @param string $domain Unique identifier for retrieving translated strings 466 * @param string $mu_plugin_rel_path Relative to WPMU_PLUGIN_DIR directory in which 467 * the MO file resides. Defaults to empty string. 487 * @param string $domain Unique identifier for retrieving translated strings. 488 * @param string $mu_plugin_rel_path Relative to WPMU_PLUGIN_DIR directory in which the .mo file resides. 489 * Default empty string. 490 * @return bool True when textdomain is successfully loaded, false otherwise. 468 491 */ 469 492 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 470 493 $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); … … 481 504 } 482 505 483 506 /** 484 * Load sthe theme's translated strings.507 * Load the theme's translated strings. 485 508 * 486 509 * If the current locale exists as a .mo file in the theme's root directory, it 487 510 * will be included in the translated strings by the $domain. … … 490 513 * 491 514 * @since 1.5.0 492 515 * 493 * @param string $domain Unique identifier for retrieving translated strings 516 * @param string $domain Unique identifier for retrieving translated strings. 517 * @return bool True when textdomain is successfully loaded, false otherwise. 494 518 */ 495 519 function load_theme_textdomain( $domain, $path = false ) { 496 520 $locale = apply_filters( 'theme_locale', get_locale(), $domain ); … … 509 533 } 510 534 511 535 /** 512 * Load sthe child themes translated strings.536 * Load the child themes translated strings. 513 537 * 514 * If the current locale exists as a .mo file in the child themes root directory, it515 * will be included in the translated strings by the $domain.538 * If the current locale exists as a .mo file in the child themes 539 * root directory, it will be included in the translated strings by the $domain. 516 540 * 517 541 * The .mo files must be named based on the locale exactly. 518 542 * 519 543 * @since 2.9.0 520 544 * 521 * @param string $domain Unique identifier for retrieving translated strings 545 * @param string $domain Unique identifier for retrieving translated strings. 546 * @return bool True when the theme textdomain is successfully loaded, false otherwise. 522 547 */ 523 548 function load_child_theme_textdomain( $domain, $path = false ) { 524 549 if ( ! $path ) … … 527 552 } 528 553 529 554 /** 530 * Returns the Translations instance for a domain. If there isn't one, 531 * returns empty Translations instance. 555 * Return the Translations instance for a domain. 532 556 * 533 * @param string $domain 534 * @return object A Translation instance 557 * If there isn't one, returns empty Translations instance. 558 * 559 * @param string $domain Unique identifier for retrieving translated strings. 560 * @return Translations A Translations instance. 535 561 */ 536 562 function get_translations_for_domain( $domain ) { 537 563 global $l10n; … … 545 571 * Whether there are translations for the domain 546 572 * 547 573 * @since 3.0.0 548 * @param string $domain 549 * @return bool Whether there are translations 574 * @param string $domain Unique identifier for retrieving translated strings. 575 * @return bool Whether there are translations. 550 576 */ 551 577 function is_textdomain_loaded( $domain ) { 552 578 global $l10n; … … 554 580 } 555 581 556 582 /** 557 * Translates role name. Since the role names are in the database and 558 * not in the source there are dummy gettext calls to get them into the POT 559 * file and this function properly translates them back. 583 * Translates role name. 560 584 * 585 * Since the role names are in the database and not in the source there 586 * are dummy gettext calls to get them into the POT file and this function 587 * properly translates them back. 588 * 561 589 * The before_last_bar() call is needed, because older installs keep the roles 562 590 * using the old context format: 'Role name|User role' and just skipping the 563 591 * content after the last bar is easier than fixing them in the DB. New installs 564 592 * won't suffer from that problem. 593 * 594 * @since 2.8.0 595 * 596 * @param string $name The role name. 597 * @return string Translated role name on success, original name on failure. 565 598 */ 566 599 function translate_user_role( $name ) { 567 600 return translate_with_gettext_context( before_last_bar($name), 'User role' ); 568 601 } 569 602 570 603 /** 571 * Get all available languages based on the presence of *.mo files in a given directory. The default directory is WP_LANG_DIR.604 * Get all available languages based on the presence of *.mo files in a given directory. 572 605 * 606 * The default directory is WP_LANG_DIR. 607 * 573 608 * @since 3.0.0 574 609 * 575 * @param string $dir A directory in which to search for language files. The default directory is WP_LANG_DIR. 576 * @return array Array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names. 610 * @param string $dir A directory to search for language files. 611 * Default WP_LANG_DIR. 612 * @return array An array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names. 577 613 */ 578 614 function get_available_languages( $dir = null ) { 579 615 $languages = array(); … … 586 622 } 587 623 588 624 return $languages; 589 } 590 No newline at end of file 625 }