_nx()获取对单复数进行翻译后的字符串

目录

描述

A hybrid of _n() and _x(). It supports contexts and plurals.

_nx() 描述

用法

<?php _nx$single$plural$number$context$domain ?>

_nx() 用法

参数

$single

(string) (必填) The text that will be used if $number is 1

默认值: None

$plural

(string) (必填) The text that will be used if $number is not 1

默认值: None

$number

(int) (必填) The number to compare against to use either $single or $plural

默认值: None

$context

(string) (必填) Context information for the translators

默认值: None

$domain

(string) (可选) Domain to retrieve the translated text

默认值: 'default'

_nx() 参数

返回值

(string) 

Either $single or $plural translated context string.

_nx() 返回值

注意

  • 使用到 the 'ngettext_with_context' 过滤器.
  • l10n is an abbreviation for localization.

_nx() 注意

历史

  • 添加于 版本: 3.0.0

_nx() 历史

源文件

_nx() 函数的代码位于 wp-includes/l10n.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the plural or single form based on the supplied amount with gettext context.
 *
 * This is a hybrid of _n() and _x(). It supports contexts and plurals.
 *
 * @since 2.8.0
 *
 * @param string $single  The text that will be used if $number is 1.
 * @param string $plural  The text that will be used if $number is not 1.
 * @param int    $number  The number to compare against to use either $single or $plural.
 * @param string $context Context information for the translators.
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
 * @return string Either $single or $plural translated text with context.
 */
function _nx($single, $plural, $number, $context, $domain = 'default') {
	$translations = get_translations_for_domain( $domain );
	$translation = $translations->translate_plural( $single, $plural, $number, $context );
	/**
	 * Filter text with its translation while plural option and context are available.
	 *
	 * @since 2.8.0
	 *
	 * @param string $translation Translated text.
	 * @param string $single      The text that will be used if $number is 1.
	 * @param string $plural      The text that will be used if $number is not 1.
	 * @param string $number      The number to compare against to use either $single or $plural.
	 * @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 );
}

_nx() 源文件

相关