ngettext_{$domain}
云策文档标注
概述
ngettext_{$domain} 是一个 WordPress 过滤器钩子,用于过滤特定文本域中字符串的单数或复数形式。它允许开发者自定义翻译逻辑,基于数字参数选择单数或复数文本。
关键要点
- 钩子名称中的 $domain 是动态部分,指代文本域,用于唯一标识翻译字符串。
- 参数包括 $translation(已翻译文本)、$single(单数文本)、$plural(复数文本)、$number(数字)和 $domain(文本域)。
- 通过 apply_filters 调用,常用于 _n() 函数中,基于数字选择单数或复数形式。
- 自 WordPress 5.5.0 版本引入。
原文内容
Filters the singular or plural form of a string for a domain.
Description
The dynamic portion of the hook name, $domain, refers to the text domain.
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_{$domain}", $translation, $single, $plural, $number, $domain );
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |