_nx_noop() WordPress Function

The nx_noop() function is a utility function that allows you to create and return a no-op (no operation) function. This can be useful when you need a placeholder function that doesn't actually do anything.

_nx_noop( string $singular, string $plural, string $context, string $domain = null ) #

Registers plural strings with gettext context in POT file, but does not translate them.


Description

Used when you want to keep structures with translatable plural strings and use them later when the number is known.

Example of a generic phrase which is disambiguated via the context parameter:

$messages = array(
     'people'  => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
     'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
);
...
$message = $messages[ $type ];
printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );

Top ↑

Parameters

$singular

(string)(Required)Singular form to be localized.

$plural

(string)(Required)Plural form to be localized.

$context

(string)(Required)Context information for the translators.

$domain

(string)(Optional) Text domain. Unique identifier for retrieving translated strings.

Default value: null


Top ↑

Return

(array) Array of translation information for the strings.

  • (string) Singular form to be localized. No longer used.
  • '1'
    (string) Plural form to be localized. No longer used.
  • '2'
    (string) Context information for the translators. No longer used.
  • 'singular'
    (string) Singular form to be localized.
  • 'plural'
    (string) Plural form to be localized.
  • 'context'
    (string) Context information for the translators.
  • 'domain'
    (string|null) Text domain.


Top ↑

Source

File: wp-includes/l10n.php

function _nx_noop( $singular, $plural, $context, $domain = null ) {
	return array(
		0          => $singular,
		1          => $plural,
		2          => $context,
		'singular' => $singular,
		'plural'   => $plural,
		'context'  => $context,
		'domain'   => $domain,
	);
}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.