返回介绍

_nx()

发布于 2017-09-11 13:28:14 字数 4231 浏览 1159 评论 0 收藏 0

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

Translates and retrieves the singular or plural form based on the supplied number, with gettext context.


description

This is a hybrid of _n() and _x(). It supports context and plurals.

Used when you want to use the appropriate form of a string with context based on whether a number is singular or plural.

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

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) (Required) The text to be used if the number is singular.

$plural

(string) (Required) The text to be used if the number is plural.

$number

(int) (Required) The number to compare against to use either the singular or plural form.

$context

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

$domain

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

Default value: 'default'


返回值

(string) The translated singular or plural form.


源代码

File: wp-includes/l10n.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 string $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.
	 */
	return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: get_translations_for_domain()
  • wp-includes/l10n.php: ngettext_with_context
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/pomo/translations.php: Translations::translate_plural()

Used By

  • wp-admin/includes/class-wp-ms-users-list-table.php: WP_MS_Users_List_Table::get_views()
  • wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::get_views()
  • wp-admin/includes/class-wp-ms-themes-list-table.php: WP_MS_Themes_List_Table::get_views()
  • wp-admin/includes/dashboard.php: wp_dashboard_right_now()
  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::get_views()
  • wp-admin/includes/ajax-actions.php: _wp_ajax_delete_comment_response()
  • wp-admin/includes/ajax-actions.php: wp_ajax_replyto_comment()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::get_views()
  • wp-includes/l10n.php: translate_nooped_plural()
  • Show 4 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文