我没有看到任何钩子,但你可以用gettext 过滤器挂钩。将以下函数添加到主题的函数中。php应该做到这一点。代替text-domain
使用主题的文本域
if ( ! function_exists( \'my_gettext\' ) ) {
function my_gettext( $translated_text, $untranslated_text, $domain ) {
global $pagenow;
if ( $pagenow === \'wp-comments-post.php\' ) {
switch ( $untranslated_text ) {
case \'<strong>ERROR</strong>: please fill the required fields (name, email).\' :
$translated_text = __( \'<strong>ERROR</strong>: please fill the required fields (name, email).<br /><a href="javascript:javascript:history.go(-1)">Back to XYZ Article</a>\', \'text-domain\' );
break;
}
}
return $translated_text;
}
}
add_filter( \'gettext\', \'my_gettext\', 20, 3 );
该函数查找
case
在wp评论帖子中。php并将其替换为
$translated_text
.
缺点是,我们通常不会在国际化函数中包含HTML,但拆分它却不起作用。因此,以下内容将引发错误:
$translated_text = \'<strong>\' . __( \'ERROR\', \'text-domain\' ) . \'</strong>:\' . __( \'please fill the required fields (name, email).\', \'text-domain\' ) . \'<br /><a href="javascript:javascript:history.go(-1)">\' . __( \'Back to XYZ Article\', \'text-domain\' ) . \'</a>\';
<小时>
UPDATE following Pieter\'s comment
记录在案
sprinf
确实没有必要在国际化函数中包含HTML。。。
if ( ! function_exists( \'my_gettext\' ) ) {
function my_gettext( $translated_text, $untranslated_text, $domain ) {
global $pagenow;
if ( $pagenow === \'wp-comments-post.php\' ) {
switch ( $untranslated_text ) {
case \'<strong>ERROR</strong>: please fill the required fields (name, email).\' :
$translated_text = sprintf( __( \'%1$s: please fill the required fields (name, email).%2$s\', \'text-domain\' ), \'<strong>\' . __( \'ERROR\', \'text-domain\' ) . \'</strong>\', \'<br /><a href="javascript:javascript:history.go(-1)">\' . __( \'Back to XYZ Article\', \'text-domain\' ) . \'</a>\' );
break;
}
}
return $translated_text;
}
}
add_filter( \'gettext\', \'my_gettext\', 20, 3 );