# _nx()

URL: https://chugunov.pro/api-wordpress/functions/_nx/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.5.0.

## Сигнатура

```php
_nx( string $single, string $plural, int $number, string $context, string $domain = 'default' ): string
```

## Описание

Это гибрид _n() и _x() . Поддерживает контекст и множественное число.
Используется, когда нужно выбрать подходящую форму строки с контекстом в зависимости от того, единственное это число или множественное.
Пример обобщённой фразы, которая уточняется через параметр контекста:
printf( _nx( '%s group', '%s groups', $people, 'group of people', 'text-domain' ), number_format_i18n( $people ) );
printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) );

## Параметры

- `$single` `string` — обязательный. Текст, используемый, если число в единственном числе.
- `$plural` `string` — обязательный. Текст, используемый, если число во множественном числе.
- `$number` `int` — обязательный. Число, по которому выбирается форма единственного или множественного числа.
- `$context` `string` — обязательный. Контекстная информация для переводчиков.
- `$domain` `string` — необязательный, по умолчанию `'default'`. Текстовый домен. Уникальный идентификатор для получения переведённых строк.
  
  Значение по умолчанию: 'default'.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/l10n.php:542`

```php
function _nx( $single, $plural, $number, $context, $domain = 'default' ) {
	$translations = get_translations_for_domain( $domain );
	$translation  = $translations->translate_plural( $single, $plural, $number, $context );

	/**
	 * Filters the singular or plural form of a string with gettext context.
	 *
	 * @since 2.8.0
	 *
	 * @param string $translation Translated text.
	 * @param string $single      The text to be used if the number is singular.
	 * @param string $plural      The text to be used if the number is plural.
	 * @param int    $number      The number to compare against to use either the singular or plural form.
	 * @param string $context     Context information for the translators.
	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
	 */
	$translation = apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );

	/**
	 * Filters the singular or plural form of a string with gettext context for a domain.
	 *
	 * The dynamic portion of the hook name, `$domain`, refers to the text domain.
	 *
	 * @since 5.5.0
	 *
	 * @param string $translation Translated text.
	 * @param string $single      The text to be used if the number is singular.
	 * @param string $plural      The text to be used if the number is plural.
	 * @param int    $number      The number to compare against to use either the singular or plural form.
	 * @param string $context     Context information for the translators.
	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
	 */
	$translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain );

	return $translation;
}
```

## История изменений

- 5.5.0 — Introduced ngettext_with_context-{$domain} filter.
- 2.8.0 — Introduced.

## Связанные

Использует: [`get_translations_for_domain`](https://chugunov.pro/api-wordpress/functions/get_translations_for_domain/), `Translations::translate_plural`, [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_Privacy_Requests_Table::get_views`, `WP_MS_Users_List_Table::get_views`, `WP_Plugins_List_Table::get_views`, `WP_MS_Themes_List_Table::get_views`, [`install_plugin_information`](https://chugunov.pro/api-wordpress/functions/install_plugin_information/), `WP_Plugin_Install_List_Table::display_rows`, `WP_Users_List_Table::get_views`, `WP_Posts_List_Table::get_views`, [`translate_nooped_plural`](https://chugunov.pro/api-wordpress/functions/translate_nooped_plural/), [`_n_noop`](https://chugunov.pro/api-wordpress/functions/_n_noop/), [`_nx_noop`](https://chugunov.pro/api-wordpress/functions/_nx_noop/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_nx/
