Skip to main content
improved function (added sprintf)
Source Link
Axel
  • 156
  • 4

I don't see any hook there, but you could use the gettext filter hook. Adding the following function to your theme's functions.php should do the trick. Replace text-domain with your theme's 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 );
The function looks for the `case` in wp-comments-post.php and replaces it with the `$translated_text`.

The downside is that we would normally not include HTML in internationalization functions, yet splitting it doesn't work. So, the following would throw an error:

$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

Just for the record, with sprinf it is indeed not necessary to include HTML in internationalization functions...

<?php
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( __( '<strong>ERROR</strong>'%1$s: please fill the required fields (name, email).<br%2$s', 'text-domain' ), '<strong>' . __( 'ERROR', 'text-domain' ) . '</strong>', '<br /><a href="javascript:javascript:history.go(-1)">Back">' . __( 'Back to XYZ Article</a>'Article', 'text-domain' ) . '</a>' );
                    break;
            }
        }
        return $translated_text;
    }
}
add_filter( 'gettext', 'my_gettext', 20, 3 );
?>

The function looks for the case in wp-comments-post.php and replaces it with the $translated_text.

The downside is that we would normally not include HTML in internationalization functions, yet splitting it doesn't work. So, the following would throw an error:

<?php
$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>';
?>

I don't see any hook there, but you could use the gettext filter hook. Adding the following function to your theme's functions.php should do the trick. Replace text-domain with your theme's text domain.

<?php
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 );
?>

The function looks for the case in wp-comments-post.php and replaces it with the $translated_text.

The downside is that we would normally not include HTML in internationalization functions, yet splitting it doesn't work. So, the following would throw an error:

<?php
$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>';
?>

I don't see any hook there, but you could use the gettext filter hook. Adding the following function to your theme's functions.php should do the trick. Replace text-domain with your theme's 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 );
The function looks for the `case` in wp-comments-post.php and replaces it with the `$translated_text`.

The downside is that we would normally not include HTML in internationalization functions, yet splitting it doesn't work. So, the following would throw an error:

$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

Just for the record, with sprinf it is indeed not necessary to include HTML in internationalization functions...

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 );
Source Link
Axel
  • 156
  • 4

I don't see any hook there, but you could use the gettext filter hook. Adding the following function to your theme's functions.php should do the trick. Replace text-domain with your theme's text domain.

<?php
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 );
?>

The function looks for the case in wp-comments-post.php and replaces it with the $translated_text.

The downside is that we would normally not include HTML in internationalization functions, yet splitting it doesn't work. So, the following would throw an error:

<?php
$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>';
?>