函数文档

_n_noop()

💡 云策文档标注

概述

_n_noop() 函数用于在 POT 文件中注册复数形式的可翻译字符串,但不进行实际翻译。它适用于需要根据数量动态选择单复数形式的场景,返回一个包含翻译信息的数组供后续使用。

关键要点

  • 注册复数字符串到 POT 文件,但不翻译,常用于延迟翻译场景。
  • 接受三个参数:$singular(单数形式)、$plural(复数形式)和可选的 $domain(文本域)。
  • 返回一个数组,包含单数、复数形式和文本域等信息,可与 translate_nooped_plural() 配合使用。
  • 自 WordPress 2.5.0 版本引入,是国际化开发中的辅助函数。

代码示例

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

📄 原文内容

Registers plural strings in POT file, but does not translate them.

Description

Used when you want to keep structures with translatable plural strings and use them later when the number is known.

Example:

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

Parameters

$singularstringrequired
Singular form to be localized.
$pluralstringrequired
Plural form to be localized.
$domainstringoptional
Text domain. Unique identifier for retrieving translated strings.

Default:null

Return

array Array of translation information for the strings.

  • 0 string
    Singular form to be localized. No longer used.
  • 1 string
    Plural form to be localized. No longer used.
  • singular string
    Singular form to be localized.
  • plural string
    Plural form to be localized.
  • context null
    Context information for the translators.
  • domain string|null
    Text domain.

Source

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

Changelog

Version Description
2.5.0 Introduced.