On this page
_n( string $single, string $plural, int $number, string $domain = 'default' ): string
Translates and retrieves the singular or plural form based on the supplied number.
Description
Used when you want to use the appropriate form of a string based on whether a number is singular or plural.
Example:
printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
Parameters
$singlestring Required-
The text to be used if the number is singular.
$pluralstring Required-
The text to be used if the number is plural.
$numberint Required-
The number to compare against to use either the singular or plural form.
$domainstring Optional-
Text domain. Unique identifier for retrieving translated strings.
Default'default'.Default:
'default'
Return
string The translated singular or plural form.
Source
File: wp-includes/l10n.php. View all references
function _n( $single, $plural, $number, $domain = 'default' ) {
$translations = get_translations_for_domain( $domain );
$translation = $translations->translate_plural( $single, $plural, $number );
/**
* Filters the singular or plural form of a string.
*
* @since 2.2.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 $domain Text domain. Unique identifier for retrieving translated strings.
*/
$translation = apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
/**
* Filters the singular or plural form of a string 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 $domain Text domain. Unique identifier for retrieving translated strings.
*/
$translation = apply_filters( "ngettext_{$domain}", $translation, $single, $plural, $number, $domain );
return $translation;
}
Hooks
- apply_filters( 'ngettext',
string $translation ,string $single ,string $plural ,int $number ,string $domain ) -
Filters the singular or plural form of a string.
- apply_filters( "ngettext_{$domain}",
string $translation ,string $single ,string $plural ,int $number ,string $domain ) -
Filters the singular or plural form of a string for a domain.
Related
Uses
| Uses | Description |
|---|---|
| get_translations_for_domain() wp-includes/l10n.php | Returns the Translations instance for a text domain. |
| Translations::translate_plural() wp-includes/pomo/translations.php | |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| WP_Site_Health::get_test_page_cache() wp-admin/includes/class-wp-site-health.php | Tests if a full page cache is available. |
| rest_validate_object_value_from_schema() wp-includes/rest-api.php | Validates an object value based on a schema. |
| rest_validate_array_value_from_schema() wp-includes/rest-api.php | Validates an array value based on a schema. |
| rest_validate_string_value_from_schema() wp-includes/rest-api.php | Validates a string value based on a schema. |
| wp_dashboard_site_health() wp-admin/includes/dashboard.php | Displays the Site Health Status widget. |
| WP_Site_Health::get_test_plugin_version() wp-admin/includes/class-wp-site-health.php | Tests if plugins are outdated, or unnecessary. |
| WP_Site_Health::get_test_theme_version() wp-admin/includes/class-wp-site-health.php | Tests if themes are outdated, or unnecessary. |
| human_readable_duration() wp-includes/functions.php | Converts a duration to human readable format. |
| WP_Privacy_Requests_Table::process_bulk_action() wp-admin/includes/class-wp-privacy-requests-table.php | Process bulk actions. |
| WP_Widget_Custom_HTML::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-custom-html.php | Loads the required scripts and styles for the widget control. |
| WP_Customize_Manager::save_changeset_post() wp-includes/class-wp-customize-manager.php | Saves the post for the loaded changeset. |
| print_embed_comments_button() wp-includes/embed.php | Prints the necessary markup for the embed comments button. |
| WP_Customize_Nav_Menus::enqueue_scripts() wp-includes/class-wp-customize-nav-menus.php | Enqueues scripts and styles for Customizer pane. |
| WP_Customize_Nav_Menus::customize_register() wp-includes/class-wp-customize-nav-menus.php | Adds the customizer settings and controls. |
| get_comments_number_text() wp-includes/comment-template.php | Displays the language string for the number of comments the current post has. |
| WP_MS_Users_List_Table::get_views() wp-admin/includes/class-wp-ms-users-list-table.php | |
| WP_Screen::render_screen_layout() wp-admin/includes/class-wp-screen.php | Renders the option for number of columns on the page. |
| WP_Plugins_List_Table::get_views() wp-admin/includes/class-wp-plugins-list-table.php | |
| WP_List_Table::ajax_response() wp-admin/includes/class-wp-list-table.php | Handles an incoming ajax request (called from admin-ajax.php) |
| WP_List_Table::comments_bubble() wp-admin/includes/class-wp-list-table.php | Displays a comment count bubble. |
| WP_List_Table::pagination() wp-admin/includes/class-wp-list-table.php | Displays the pagination. |
| WP_MS_Themes_List_Table::get_views() wp-admin/includes/class-wp-ms-themes-list-table.php | |
| install_plugin_information() wp-admin/includes/plugin-install.php | Displays plugin information in dialog box form. |
| wp_dashboard_right_now() wp-admin/includes/dashboard.php | Dashboard widget that displays some basic stats about the site. |
| wp_network_dashboard_right_now() wp-admin/includes/dashboard.php | |
| wp_star_rating() wp-admin/includes/template.php | Outputs a HTML element with a star rating for a given rating. |
| WP_Users_List_Table::single_row() wp-admin/includes/class-wp-users-list-table.php | Generate HTML for a single row on the users.php admin panel. |
| _wp_ajax_delete_comment_response() wp-admin/includes/ajax-actions.php | Sends back current comment total and new page links if they need to be updated. |
| wp_ajax_replyto_comment() wp-admin/includes/ajax-actions.php | Ajax handler for replying to a comment. |
| translate_nooped_plural() wp-includes/l10n.php | Translates and returns the singular or plural form of a string that’s been registered with _n_noop() or _nx_noop() . |
| human_time_diff() wp-includes/formatting.php | Determines the difference between two timestamps. |
| wp_notify_moderator() wp-includes/pluggable.php | Notifies the moderator of the site about a new comment that is awaiting approval. |
| __ngettext() wp-includes/deprecated.php | Retrieve the plural or single form based on the amount. |
| _nc() wp-includes/deprecated.php | Legacy version of _n() , which supports contexts. |
| wp_get_update_data() wp-includes/update.php | Collects counts and UI strings for available updates. |
| wp_admin_bar_comments_menu() wp-includes/admin-bar.php | Adds edit comments link with awaiting moderation count bubble. |
| wp_admin_bar_updates_menu() wp-includes/admin-bar.php | Provides an update link if theme/plugin/core updates are available. |
| wpmu_validate_blog_signup() wp-includes/ms-functions.php | Processes new site registrations. |
| comments_popup_link() wp-includes/comment-template.php | Displays the link to the comments for the current post ID. |
| WP_Customize_Widgets::enqueue_scripts() wp-includes/class-wp-customize-widgets.php | Enqueues scripts and styles for Customizer panel and export data to JavaScript. |
| wp_default_scripts() wp-includes/script-loader.php | Registers all WordPress scripts. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_n