根据提供的数字翻译和检索单数或复数形式。
原型
_n( string $single, string $plural, int $number, string $domain = 'default' )
描述
当你想根据数字是单数还是复数时使用相应形式的字符串时使用。
参数
$single
(string)
(Required)
如果数字是单数,则使用的文本。
$plural
(string)
(Required)
如果数字是复数则使用的文本。
$number
(int)
(Required)
要使用单数或复数形式进行比较的数字。
$domain
(string)
(Optional)
文字域名。用于检索已翻译字符串的唯一标识符
返回值
(string)
翻译的单数或复数形式。
源文件
路径:wp-includes/l10n.php
<?php
...
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 string $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.
*/
return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/_n/