WordPress函数:国际化 _nx_noop 在 pot 中注册字符串

江河/ 04月18日/ WordPress/ 浏览 121

函数原型:


_nx_noop( string $singular, string $plural, string $context, string $domain = null ): array


在POT文件中使用gettext上下文注册多个字符串,但不翻译它们。


当您希望保留具有可翻译复数字符串的结构,并在以后知道数字时使用它们时使用。


通过上下文参数消除歧义的通用短语的示例:


$messages = array(
     'people'  => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
     'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
);
...
$message = $messages[ $type ];
printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );


参数说明:


$singular 要局部化的奇异形式。


$plural 复数形式要本地化。


$context 为翻译提供上下文。


$domain 文本域。用于检索翻译字符串的唯一标识符。


返回值:


string 要局部化的奇异形式。不再使用。


1 string 复数形式要本地化。不再使用。


2 string 为翻译人员提供上下文信息。不再使用。


singular string 要局部化的奇异形式。


plural string 复数形式要本地化。


context null 为翻译人员提供上下文信息。


domain string|null 文本域。


函数源码:


function _nx_noop( $singular, $plural, $context, $domain = null ) {
	return array(
		0          => $singular,
		1          => $plural,
		2          => $context,
		'singular' => $singular,
		'plural'   => $plural,
		'context'  => $context,
		'domain'   => $domain,
	);
}


使用举例:


$labels = array(
	'draft' => array( _nx_noop( '%s Draft', '%s Drafts', 'post' ), _nx_noop( '%s Draft', '%s Drafts', 'page' ) ),
	'publish' => array( _nx_noop( '%s Published', '%s Published', 'post' ), _nx_noop( '%s Published', '%s Published', 'page' ) ),
);
if ( $post_type == 'page' ) {
	$labels = $labels[ $post_status ][1];
} else {
	$labels = $labels[ $post_status ][0];
}
$usable_text = sprintf( translate_nooped_plural( $labels, $count, $domain ), $count );


发表评论

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

客服 工单