ngettext_with_context
云策文档标注
概述
ngettext_with_context 是一个 WordPress 过滤器钩子,用于在 gettext 上下文中过滤字符串的单数或复数形式。它通常与 _nx() 函数结合使用,处理翻译时的上下文和复数形式。
关键要点
- 过滤器应用于翻译文本,参数包括 $translation(翻译后的文本)、$single(单数文本)、$plural(复数文本)、$number(数字)、$context(上下文)和 $domain(文本域)。
- 此钩子始终运行,即使国际化未启用或文本域未加载,可能导致性能问题。
- 相关函数包括 _nx()(用于带上下文的单复数翻译)、_n()(单复数翻译)和 gettext_with_context(上下文翻译过滤器)。
注意事项
- 注意性能影响:由于过滤器总是执行,如果钩子函数过多,可能影响网站速度。
- 正确使用参数:确保传递正确的 $number、$context 和 $domain 以匹配翻译需求。
原文内容
Filters the singular or plural form of a string with gettext context.
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.
$contextstring-
Context information for the translators.
$domainstring-
Text domain. Unique identifier for retrieving translated strings.
Source
$translation = apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |