钩子文档

ngettext_with_context_{$domain}

💡 云策文档标注

概述

ngettext_with_context_{$domain} 是一个 WordPress 过滤器钩子,用于在特定文本域下过滤带有 gettext 上下文的字符串的单数或复数形式。它允许开发者自定义翻译文本,基于数字和上下文条件。

关键要点

  • 这是一个动态钩子,钩子名称中的 $domain 部分指代文本域,用于唯一标识翻译字符串。
  • 钩子参数包括 $translation(已翻译文本)、$single(单数文本)、$plural(复数文本)、$number(数字)、$context(上下文信息)和 $domain(文本域)。
  • 主要用于 _nx() 函数,在 wp-includes/l10n.php 中实现,基于数字和上下文提供单数或复数形式的翻译。
  • 自 WordPress 5.5.0 版本引入。

代码示例

$translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain );

📄 原文内容

Filters the singular or plural form of a string with gettext context 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.
$contextstring
Context information for the translators.
$domainstring
Text domain. Unique identifier for retrieving translated strings.

Source

$translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain );

Changelog

Version Description
5.5.0 Introduced.