函数文档

_nc()

💡 云策文档标注

概述

_nc() 是 _n() 的旧版本函数,支持上下文翻译,用于根据数字返回单数或复数形式的翻译字符串。该函数已被弃用,建议使用 _nx() 替代。

关键要点

  • _nc() 是 _n() 的遗留版本,支持通过管道符分隔上下文
  • 函数已被弃用,从 WordPress 3.0.0 起推荐使用 _nx()
  • 参数包括 $single(单数文本)、$plural(复数文本)、$number(数字)和 $domain(文本域)
  • 返回翻译后的单数或复数形式字符串

代码示例

function _nc( $single, $plural, $number, $domain = 'default' ) {
    _deprecated_function( __FUNCTION__, '2.9.0', '_nx()' );
    return before_last_bar( _n( $single, $plural, $number, $domain ) );
}

注意事项

  • 使用 _nc() 会触发 _deprecated_function() 警告,建议更新代码以避免兼容性问题
  • 函数内部调用 before_last_bar() 去除翻译字符串中最后一个管道符后的内容

📄 原文内容

Legacy version of _n() , which supports contexts.

Description

Strips everything from the translation after the last bar.

See also

Parameters

$singlestringrequired
The text to be used if the number is singular.
$pluralstringrequired
The text to be used if the number is plural.
$numberintrequired
The number to compare against to use either the singular or plural form.
$domainstringoptional
Text domain. Unique identifier for retrieving translated strings.
Default 'default'.

Return

string The translated singular or plural form.

Source

function _nc( $single, $plural, $number, $domain = 'default' ) {
	_deprecated_function( __FUNCTION__, '2.9.0', '_nx()' );
	return before_last_bar( _n( $single, $plural, $number, $domain ) );
}

Changelog

Version Description
3.0.0 Deprecated. Use _nx()
2.7.0 Introduced.