_nx()

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

描述

_ n ()和 _ x ()的混合体。它支持上下文和复数。

用法

<?php _nx( $single, $plural, $number, $context, $domain ) ?>

参数

$single

(string) (必填) 如果 $number 为1将使用的文本

默认值: None

$plural

(string) (必填) 如果 $number 不是1将使用的文本

默认值: None

$number

(int) (必填) 要比较的数字,以使用 $single 或 $multi

默认值: None

$context

(string) (必填) 翻译人员的上下文信息

默认值: None

$domain

(string) (可选) 域检索翻译后的文本

默认值: ‘default’

返回值

(string) 

Either $single or $plural translated context string.

注意

使用到 the ‘ngettext_with_context’ 过滤器.

l10n is an abbreviation for localization.

历史

添加于 版本: 3.0.0

源文件

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

/* ———————————-
* wordpress函数 星空站长网收集
* ———————————- */
/**
* 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 );

}
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索