从获取的文本中返回翻译的字符串
描述
使用 gettext 上下文检索已翻译的字符串
很多时候,在两个以上的地方发现的类似可翻译文本会发生冲突,但翻译的上下文不同。
通过在 pot 文件中包含上下文,翻译器可以以不同的方式翻译这两个字符串。
用法
<?php $translated_text = _x( $text, $context, $domain ) ?>
参数
$text
(string) (必填) 要翻译的文本
默认值: None
$context
(string) (必填) 译员的上下文信息
默认值: None
$domain
(string) (可选) 用于检索已翻译文本的域
默认值: ‘default’
返回值
(string)
已翻译的上下文字符串。
示例
$translated = _x( ‘Read’, ‘past participle: books I have read’ );
由于字符串“Read”本身在英语中可能具有几种不同含义之一,因此给出了上下文,以便翻译人员知道他们应该提供一个简短的术语,意思是“我读过的书”。
注意
L10N 是本地化的缩写。
历史
添加于 版本: 2.8.0
源文件
_x() 函数的代码位于 wp-includes/l10n.php
.
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Retrieve translated string with gettext context.
*
* Quite a few times, there will be collisions with similar translatable text
* found in more than two places, but with different translated context.
*
* By including the context in the pot file, translators can translate the two
* strings differently.
*
* @since 2.8.0
*
* @param string $text Text to translate.
* @param string $context Context information for the translators.
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
* @return string Translated context string without pipe.
*/
function _x( $text, $context, $domain = ‘default’ ) {
return translate_with_gettext_context( $text, $context, $domain );
}