_c()
云策文档标注
概述
_c() 函数用于在翻译字符串中处理竖线分隔的上下文,以解决相似可翻译文本在不同上下文中的冲突问题。该函数已被弃用,建议使用 _x() 替代。
关键要点
- _c() 函数通过竖线('|')分隔上下文,返回竖线前的翻译字符串部分。
- 如果翻译文本中没有竖线,则返回整个字符串。
- 该函数在 WordPress 2.9.0 版本中被弃用,推荐使用 _x() 函数。
- 函数参数包括必需的 $text 字符串和可选的 $domain 字符串。
- 返回值为去除竖线后的翻译上下文字符串。
代码示例
function _c( $text, $domain = 'default' ) {
_deprecated_function( __FUNCTION__, '2.9.0', '_x()' );
return before_last_bar( translate( $text, $domain ) );
}注意事项
- _c() 函数已弃用,开发者应迁移到 _x() 以避免未来兼容性问题。
- 使用竖线分隔上下文时,确保翻译字符串格式正确,否则可能影响翻译结果。
原文内容
Retrieve translated string with vertical bar context
Description
Quite a few times, there will be collisions with similar translatable text found in more than two places but with different translated context.
In order to use the separate contexts, the _c() function is used and the translatable string uses a pipe (‘|’) which has the context the string is in.
When the translated string is returned, it is everything before the pipe, not including the pipe character. If there is no pipe in the translated text then everything is returned.
See also
Parameters
$textstringrequired-
Text to translate.
$domainstringoptional-
Domain to retrieve the translated text.
Source
function _c( $text, $domain = 'default' ) {
_deprecated_function( __FUNCTION__, '2.9.0', '_x()' );
return before_last_bar( translate( $text, $domain ) );
}