__ngettext()
云策文档标注
概述
__ngettext() 是一个已弃用的 WordPress 函数,用于根据数量检索单数或复数形式。自 2.8.0 版本起,建议使用 _n() 替代。
关键要点
- __ngettext() 函数已弃用,自 WordPress 2.8.0 起应改用 _n() 函数。
- 该函数位于 wp-includes/l10n.php 文件中,用于本地化字符串的单复数处理。
- 调用 __ngettext() 会触发 _deprecated_function() 警告,提示开发者更新代码。
代码示例
function __ngettext( ...$args ) {
_deprecated_function( __FUNCTION__, '2.8.0', '_n()' );
return _n( ...$args );
}注意事项
- 在开发新插件或主题时,避免使用 __ngettext(),直接使用 _n() 以确保兼容性。
- 维护旧代码时,若遇到 __ngettext(),应将其替换为 _n() 并更新相关参数。
原文内容
Retrieve the plural or single form based on the amount.
Description
See also
Source
function __ngettext( ...$args ) { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
_deprecated_function( __FUNCTION__, '2.8.0', '_n()' );
return _n( ...$args );
}