Changeset 34781
- Timestamp:
- 10/02/2015 08:44:18 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r34778 r34781 81 81 * If there is no translation, or the text domain isn't loaded, the original text is returned. 82 82 * 83 * *Note:* Don't use {@see translate()} directly, use `{@see __()}or related functions.83 * *Note:* Don't use translate() directly, use __() or related functions. 84 84 * 85 85 * @since 2.2.0 … … 87 87 * @param string $text Text to translate. 88 88 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 89 * Default 'default'. 89 90 * @return string Translated text 90 91 */ … … 130 131 * text is returned. 131 132 * 133 * *Note:* Don't use translate_with_gettext_context() directly, use _x() or related functions. 134 * 132 135 * @since 2.8.0 133 136 * … … 135 138 * @param string $context Context information for the translators. 136 139 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 140 * Default 'default'. 137 141 * @return string Translated text on success, original text on failure. 138 142 */ … … 178 182 * @param string $text Text to translate. 179 183 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 184 * Default 'default'. 180 185 * @return string Translated text on success, original text on failure. 181 186 */ … … 193 198 * @param string $text Text to translate. 194 199 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 200 * Default 'default'. 195 201 * @return string Translated text 196 202 */ … … 206 212 * @param string $text Text to translate. 207 213 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 214 * Default 'default'. 208 215 */ 209 216 function _e( $text, $domain = 'default' ) { … … 218 225 * @param string $text Text to translate. 219 226 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 227 * Default 'default'. 220 228 */ 221 229 function esc_attr_e( $text, $domain = 'default' ) { … … 230 238 * @param string $text Text to translate. 231 239 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 240 * Default 'default'. 232 241 */ 233 242 function esc_html_e( $text, $domain = 'default' ) { … … 249 258 * @param string $context Context information for the translators. 250 259 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 260 * Default 'default'. 251 261 * @return string Translated context string without pipe. 252 262 */ … … 263 273 * @param string $context Context information for the translators. 264 274 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 275 * Default 'default'. 265 276 * @return string Translated context string without pipe. 266 277 */ … … 277 288 * @param string $context Context information for the translators. 278 289 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 290 * Default 'default'. 279 291 * @return string Translated text 280 292 */ … … 291 303 * @param string $context Context information for the translators. 292 304 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 305 * Default 'default'. 293 306 * @return string Translated text. 294 307 */ … … 298 311 299 312 /** 300 * Retrieve the plural or single form based on the supplied amount. 301 * 302 * If the text domain is not set in the $l10n list, then a comparison will be made 303 * and either $plural or $single parameters returned. 304 * 305 * If the text domain does exist, then the parameters $single, $plural, and $number 306 * will first be passed to the text domain's ngettext method. Then it will be passed 307 * to the 'ngettext' filter hook along with the same parameters. The expected 308 * type will be a string. 309 * 310 * @since 2.8.0 311 * 312 * @param string $single The text that will be used if $number is 1. 313 * @param string $plural The text that will be used if $number is not 1. 314 * @param int $number The number to compare against to use either $single or $plural. 313 * Translates and retrieves the singular or plural form based on the supplied number. 314 * 315 * Used when you want to use the appropriate form of a string based on whether a 316 * number is singular or plural. 317 * 318 * Example: 319 * 320 * $people = sprintf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) ); 321 * 322 * @since 2.8.0 323 * 324 * @param string $single The text to be used if the number is singular. 325 * @param string $plural The text to be used if the number is plural. 326 * @param int $number The number to compare against to use either the singular or plural form. 315 327 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 316 * @return string Either $single or $plural translated text. 328 * Default 'default'. 329 * @return string The translated singular or plural form. 317 330 */ 318 331 function _n( $single, $plural, $number, $domain = 'default' ) { 319 332 $translations = get_translations_for_domain( $domain ); 320 333 $translation = $translations->translate_plural( $single, $plural, $number ); 334 321 335 /** 322 * Filter t ext with its translation when plural option is available.336 * Filter the singular or plural form of a string. 323 337 * 324 338 * @since 2.2.0 325 339 * 326 340 * @param string $translation Translated text. 327 * @param string $single The text t hat will be used if $number is 1.328 * @param string $plural The text t hat will be used if $number is not 1.329 * @param string $number The number to compare against to use either $single or $plural.341 * @param string $single The text to be used if the number is singular. 342 * @param string $plural The text to be used if the number is plural. 343 * @param string $number The number to compare against to use either the singular or plural form. 330 344 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 331 345 */ … … 334 348 335 349 /** 336 * Retrieve the plural or single form based on the supplied amount with gettext context. 337 * 338 * This is a hybrid of _n() and _x(). It supports contexts and plurals. 339 * 340 * @since 2.8.0 341 * 342 * @param string $single The text that will be used if $number is 1. 343 * @param string $plural The text that will be used if $number is not 1. 344 * @param int $number The number to compare against to use either $single or $plural. 350 * Translates and retrieves the singular or plural form based on the supplied number, with gettext context. 351 * 352 * This is a hybrid of _n() and _x(). It supports context and plurals. 353 * 354 * Used when you want to use the appropriate form of a string with context based on whether a 355 * number is singular or plural. 356 * 357 * Example: 358 * 359 * $people = sprintf( _n( '%s person', '%s people', $count, 'context', 'text-domain' ), number_format_i18n( $count ) ); 360 * 361 * @since 2.8.0 362 * 363 * @param string $single The text to be used if the number is singular. 364 * @param string $plural The text to be used if the number is plural. 365 * @param int $number The number to compare against to use either the singular or plural form. 345 366 * @param string $context Context information for the translators. 346 367 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 347 * @return string Either $single or $plural translated text with context. 368 * Default 'default'. 369 * @return string The translated singular or plural form. 348 370 */ 349 371 function _nx($single, $plural, $number, $context, $domain = 'default') { 350 372 $translations = get_translations_for_domain( $domain ); 351 373 $translation = $translations->translate_plural( $single, $plural, $number, $context ); 374 352 375 /** 353 * Filter t ext with its translation while plural option and context are available.376 * Filter the singular or plural form of a string with gettext context. 354 377 * 355 378 * @since 2.8.0 356 379 * 357 380 * @param string $translation Translated text. 358 * @param string $single The text t hat will be used if $number is 1.359 * @param string $plural The text t hat will be used if $number is not 1.360 * @param string $number The number to compare against to use either $single or $plural.381 * @param string $single The text to be used if the number is singular. 382 * @param string $plural The text to be used if the number is plural. 383 * @param string $number The number to compare against to use either the singular or plural form. 361 384 * @param string $context Context information for the translators. 362 385 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 366 389 367 390 /** 368 * Register plural strings in POT file, but don't translate them.391 * Registers plural strings in POT file, but don't translate them. 369 392 * 370 393 * Used when you want to keep structures with translatable plural 371 * strings and use them later .394 * strings and use them later when the number is known. 372 395 * 373 396 * Example: 374 397 * 375 398 * $messages = array( 376 * 'post' => _n_noop( '%s post', '%s posts' ),377 * 'page' => _n_noop( '%s pages', '%s pages' ),399 * 'post' => _n_noop( '%s post', '%s posts', 'text-domain' ), 400 * 'page' => _n_noop( '%s pages', '%s pages', 'text-domain' ), 378 401 * ); 379 402 * ... 380 403 * $message = $messages[ $type ]; 381 * $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count);404 * $usable_text = sprintf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); 382 405 * 383 406 * @since 2.5.0 384 407 * 385 * @param string $singular Sing le form to be i18ned.386 * @param string $plural Plural form to be i18ned.408 * @param string $singular Singular form to be localized. 409 * @param string $plural Plural form to be localized. 387 410 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 388 * @return array array($singular, $plural) 411 * Default null. 412 * @return array { 413 * Array of translation information for the strings. 414 * 415 * @type string $0 Singular form to be localized. No longer used. 416 * @type string $1 Plural form to be localized. No longer used. 417 * @type string $singular Singular form to be localized. 418 * @type string $plural Plural form to be localized. 419 * @type null $context Context information for the translators. 420 * @type string $domain Text domain. 421 * } 389 422 */ 390 423 function _n_noop( $singular, $plural, $domain = null ) { … … 393 426 394 427 /** 395 * Register plural strings with context in POT file, but don't translate them. 396 * 397 * @since 2.8.0 398 * @param string $singular 399 * @param string $plural 400 * @param string $context 401 * @param string|null $domain 402 * @return array 428 * Register plural strings with gettext context in the POT file, but don't translate them. 429 * 430 * Used when you want to keep structures with translatable plural 431 * strings and use them later when the number is known. 432 * 433 * Example: 434 * 435 * $messages = array( 436 * 'post' => _n_noop( '%s post', '%s posts', 'context', 'text-domain' ), 437 * 'page' => _n_noop( '%s pages', '%s pages', 'context', 'text-domain' ), 438 * ); 439 * ... 440 * $message = $messages[ $type ]; 441 * $usable_text = sprintf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); 442 * 443 * @since 2.8.0 444 * 445 * @param string $singular Singular form to be localized. 446 * @param string $plural Plural form to be localized. 447 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 448 * Default null. 449 * @return array { 450 * Array of translation information for the strings. 451 * 452 * @type string $0 Singular form to be localized. No longer used. 453 * @type string $1 Plural form to be localized. No longer used. 454 * @type string $2 Context information for the translators. No longer used. 455 * @type string $singular Singular form to be localized. 456 * @type string $plural Plural form to be localized. 457 * @type string $context Context information for the translators. 458 * @type string $domain Text domain. 459 * } 403 460 */ 404 461 function _nx_noop( $singular, $plural, $context, $domain = null ) { … … 407 464 408 465 /** 409 * Translate the result of _n_noop() or _nx_noop(). 466 * Translates and retrieves the singular or plural form of a string that's been registered 467 * with _n_noop() or _nx_noop(). 468 * 469 * Used when you want to use a translatable plural string once the number is known. 470 * 471 * Example: 472 * 473 * $messages = array( 474 * 'post' => _n_noop( '%s post', '%s posts', 'text-domain' ), 475 * 'page' => _n_noop( '%s pages', '%s pages', 'text-domain' ), 476 * ); 477 * ... 478 * $message = $messages[ $type ]; 479 * $usable_text = sprintf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); 410 480 * 411 481 * @since 3.1.0 412 482 * 413 * @param array $nooped_plural Array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop()414 * @param int $count Number of objects 483 * @param array $nooped_plural Array with singular, plural, and context keys, usually the result of _n_noop() or _nx_noop(). 484 * @param int $count Number of objects. 415 485 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. If $nooped_plural contains 416 * a text domain passed to _n_noop() or _nx_noop(), it will override this value. 486 * a text domain passed to _n_noop() or _nx_noop(), it will override this value. Default 'default'. 417 487 * @return string Either $single or $plural translated text. 418 488 */
Note: See TracChangeset
for help on using the changeset viewer.