当前浏览:首页 / WordPress函数 / _nx_noop()

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

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

e 翻译more...

  • __() 检索$text的翻译
  • _e() 显示翻译文本
  • _ex() 使用gettext上下文显示翻译后的字符串
  • _n_noop() 在POT文件中注册多个字符串,但不翻译它们
  • _n() 基于提供的数字翻译和检索单数或复数形式
  • _nx_noop() 在POT文件中使用gettext上下文注册多个字符串,但不翻译它们
  • _nx() 使用gettext上下文,根据提供的数字检索单/复数形式进行翻译
  • _x() 使用gettext上下文检索已翻译的字符串
  • esc_attr__() 检索$text的翻译并将其转义,以便在属性中安全使用
  • esc_attr_e() 显示为在属性中安全使用而转义的翻译文本

esc 转义more...

  • esc_attr__() 检索$text的翻译并将其转义,以便在属性中安全使用
  • esc_attr_e() 显示为在属性中安全使用而转义的翻译文本
  • esc_attr_x() 使用gettext上下文翻译字符串,并将其转义以在属性中安全使用。
  • esc_attr() 转义HTML属性
  • esc_html__() 检索$text的翻译并将其转义,以便在HTML输出中安全使用。
  • esc_html_e() 显示为在HTML输出中安全使用而转义的翻译文本。
  • esc_html_x() 使用gettext上下文翻译字符串,并将其转义,以便在HTML输出中安全使用
  • esc_html() 转义HTML块
  • esc_js() 转义单引号、"、 、&,并修复行尾。
  • esc_textarea() 转义textarea值

noop

  • _n_noop() 在POT文件中注册多个字符串,但不翻译它们
  • _nx_noop() 在POT文件中使用gettext上下文注册多个字符串,但不翻译它们
  • translate_nooped_plural() 翻译并检索已在_n_noop()或_nx_noop()注册的字符串的单数或复数形式

描述

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

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

$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开始引入

使用示例

  • 示例1
    $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 );