_nx
函数
_nx ( $single, $plural, $number, $context, $domain = 'default' )
- 参数
-
-
(string)
$single
The text to be used if the number is singular.- Required: 是
-
(string)
$plural
The text to be used if the number is plural.- Required: 是
-
(int)
$number
The number to compare against to use either the singular or plural form.- Required: 是
-
(string)
$context
Context information for the translators.- Required: 是
-
(string)
$domain
Optional. Text domain. Unique identifier for retrieving translated strings. Default ‘default’.- Required: 否
- Default: ‘default’
-
(string)
- 返回值
-
- (string) The translated singular or plural form.
- 定义位置
-
-
wp-includes/l10n.php
, line 534
-
wp-includes/l10n.php
- 引入
- 2.8.0
- 弃用
- –
Translates and retrieves the singular or plural form based on the supplied number, with gettext context.
This is a hybrid of _n() and _x(). It supports context and plurals.
Used when you want to use the appropriate form of a string with context based on whether a
number is singular or plural.
Example of a generic phrase which is disambiguated via the context parameter:
printf( _nx( ‘%s group’, ‘%s groups’, $people, ‘group of people’, ‘text-domain’ ), number_format_i18n( $people ) );
printf( _nx( ‘%s group’, ‘%s groups’, $animals, ‘group of animals’, ‘text-domain’ ), number_format_i18n( $animals ) );
function _nx( $single, $plural, $number, $context, $domain = 'default' ) { $translations = get_translations_for_domain( $domain ); $translation = $translations->translate_plural( $single, $plural, $number, $context ); /** * Filters the singular or plural form of a string with gettext context. * * @since 2.8.0 * * @param string $translation Translated text. * @param string $single The text to be used if the number is singular. * @param string $plural The text to be used if the number is plural. * @param int $number The number to compare against to use either the singular or plural form. * @param string $context Context information for the translators. * @param string $domain Text domain. Unique identifier for retrieving translated strings. */ $translation = apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); /** * Filters the singular or plural form of a string with gettext context for a domain. * * The dynamic portion of the hook name, `$domain`, refers to the text domain. * * @since 5.5.0 * * @param string $translation Translated text. * @param string $single The text to be used if the number is singular. * @param string $plural The text to be used if the number is plural. * @param int $number The number to compare against to use either the singular or plural form. * @param string $context Context information for the translators. * @param string $domain Text domain. Unique identifier for retrieving translated strings. */ $translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain ); return $translation; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。