WordPress函数:translate_nooped_plural 翻译并注册字符串

江河/ 04月19日/ WordPress/ 浏览 155

函数原型:


translate_nooped_plural( array $nooped_plural, int $count, string $domain = ‘default’ ): string


转换并返回已用_n_noop()或_nx_noop()注册的字符串的单数或复数形式。


当您想在知道数字后使用可翻译的复数字符串时使用。


举例:


$message = _n_noop( '%s post', '%s posts', 'text-domain' );
...
printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );


参数说明:


$nooped_plural 数组,通常是_n_noop()或_nx_noop()的返回值。


$singular 单数形式


$plural 复数形式


$context 上下文


$domain 文字域


$count 数量


$domain 文本域。用于检索翻译字符串的唯一标识符。如果$nooped_plual包含一个传递给_n_noop()或_nx_noop()的文本域,它将覆盖此值。默认为“默认”。


函数源码:


function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
	if ( $nooped_plural['domain'] ) {
		$domain = $nooped_plural['domain'];
	}

	if ( $nooped_plural['context'] ) {
		return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
	} else {
		return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
	}
}





发表评论

暂无评论,抢个沙发...

客服 工单