translate_with_context()
云策文档标注
概述
translate_with_context() 是一个已弃用的 WordPress 函数,用于翻译包含上下文信息的文本,类似于 translate(),但假设文本在最后一个竖线后包含上下文。
关键要点
- 函数已弃用,自 WordPress 2.9.0 起推荐使用 _x() 替代。
- 参数包括 $text(必需,要翻译的文本)和 $domain(必需,翻译域)。
- 返回翻译后的文本字符串。
- 内部调用 before_last_bar() 和 translate() 函数。
代码示例
function translate_with_context( $text, $domain = 'default' ) {
_deprecated_function( __FUNCTION__, '2.9.0', '_x()' );
return before_last_bar( translate( $text, $domain ) );
}注意事项
- 此函数已标记为弃用,新代码应避免使用,改用 _x() 函数。
- 相关函数包括 before_last_bar()、translate() 和 _deprecated_function()。
原文内容
Translates $text like translate() , but assumes that the text contains a context after its last vertical bar.
Description
See also
Parameters
$textstringrequired-
Text to translate.
$domainstringrequired-
Domain to retrieve the translated text.
Source
function translate_with_context( $text, $domain = 'default' ) {
_deprecated_function( __FUNCTION__, '2.9.0', '_x()' );
return before_last_bar( translate( $text, $domain ) );
}