_n ( $single, $plural, $number, $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) $domain Optional. Text domain. Unique identifier for retrieving translated strings. Default 'default'.
    Required:
    Default: 'default'
返回值
  • (string) The translated singular or plural form.
定义位置
相关方法
_nc_nx____c
引入
2.8.0
弃用
-

_n: 这个函数用来翻译一个单数或复数的字符串,取决于传递的值。

根据提供的数字翻译和检索单数或复数形式。

当你想根据数字是单数还是复数来使用适当的字符串形式时使用。

例子:
printf( _n( ‘%s person’, ‘%s people’, $count, ‘text-domain’ ), number_format_i18n( $count ) );

function _n( $single, $plural, $number, $domain = 'default' ) {
	$translations = get_translations_for_domain( $domain );
	$translation  = $translations->translate_plural( $single, $plural, $number );

	/**
	 * Filters the singular or plural form of a string.
	 *
	 * @since 2.2.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 $domain      Text domain. Unique identifier for retrieving translated strings.
	 */
	$translation = apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );

	/**
	 * Filters the singular or plural form of a string 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 $domain      Text domain. Unique identifier for retrieving translated strings.
	 */
	$translation = apply_filters( "ngettext_{$domain}", $translation, $single, $plural, $number, $domain );

	return $translation;
}

常见问题

FAQs
查看更多 >