WordPress函数文档_nx()
获取对单复数进行翻译后的字符串 描述 A hybrid of _n() and _x(). It suppor…
获取对单复数进行翻译后的字符串
描述
A hybrid of _n() and _x(). It supports contexts and plurals.
用法
<?php _nx( $single, $plural, $number, $context, $domain ) ?>
参数
$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’
返回值
(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
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* 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 );
}
|
相关
L10n:
translate(),
__(),
_e(),
_n(),
_x(),
_ex(),
_nx(),
esc_attr__(),
esc_attr_e(),
esc_attr_x(),
esc_html__(),
esc_html_e(),
esc_html_x(),
_n_noop(),
_nx_noop(),
translate_nooped_plural()
- 原文:http://codex.wordpress.org/Function_Reference/_nx
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!