ngettext
云策文档标注
概述
ngettext 是一个 WordPress 过滤器钩子,用于过滤字符串的单数或复数形式,通常与国际化函数 _n() 结合使用。它允许开发者修改基于数字比较的翻译文本。
关键要点
- ngettext 过滤器应用于处理复数形式的国际化函数 _n() 的翻译文本。
- 参数包括 $translation(翻译文本)、$single(单数文本)、$plural(复数文本)、$number(比较数字)和 $domain(文本域)。
- 此过滤器始终运行,即使国际化未启用或文本域未加载,可能导致性能问题。
- 相关函数包括 _n() 用于翻译单复数形式,以及 gettext() 和 ngettext_with_context() 用于其他翻译场景。
注意事项
由于 ngettext 过滤器在任何情况下都会触发,开发者应谨慎挂钩以避免不必要的性能开销。
原文内容
Filters the singular or plural form of a string.
Parameters
$translationstring-
Translated text.
$singlestring-
The text to be used if the number is singular.
$pluralstring-
The text to be used if the number is plural.
$numberint-
The number to compare against to use either the singular or plural form.
$domainstring-
Text domain. Unique identifier for retrieving translated strings.
Source
$translation = apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
Changelog
| Version | Description |
|---|---|
| 2.2.0 | Introduced. |