描述
当您希望保留具有可翻译多个字符串的结构,并在之后知道数字时使用它们时使用。
通过上下文参数消除歧义的通用短语示例:
$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
-
(string)(必填) 要本地化的单数形式。
- $plural
-
(string)(必填) 要本地化的复数形式。
- $context
-
(string)(必填) 为翻译人员提供上下文信息。
- $domain
-
(string)(可选) 文本域。用于检索翻译字符串的唯一标识符。
默认值: null
返回
(array) 字符串的翻译信息数组。
- (string) 要本地化的单数形式。不再使用。
- '1'
(string) 要本地化的复数形式。不再使用。 - '2'
(string) 为翻译人员提供上下文信息。不再使用。 - 'singular'
(string) 要本地化的单数形式。 - 'plural'
(string) 要本地化的复数形式。 - 'context'
(string) 为翻译人员提供上下文信息。 - 'domain'
(string|null) 文本域。
源码
更新日志
版本 | 描述 |
---|---|
2.8.0 | 开始引入 |
使用示例
$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 );