Translate "Leave a comment"

We need to translate this into German. Everything else is working fine except this piece of text.

Thanks for your help in advance.

Hello Daniel,

Thanks for writing in!

Please add following code in your child theme function.php file to translate Leave a Comment:

function translate_my_text($translated) { 
    $translated = str_ireplace('Leave a comment on: "%s"', 'Read a comment translation here : "%s"', $translated);
    $translated = str_ireplace('Leave a Comment', 'Read a comment translation here', $translated);
    return $translated; 
}

To learn more about translation, please take a look at following resource.

Thanks.

Thanks for the help, we tried this and it didn’t work :frowning_face:

I’ve also noticed that the whole comment section needs translating as well.

Thanks for your help in advance!

Hey Daniel,

Please try this:

// Translate Strings
add_filter( 'gettext', 'translate_x_strings', 20, 3 );

function translate_x_strings( $translated_text, $text, $domain ) {

        switch ( $translated_text ) {

            case 'Leave a Comment' :
                $translated_text = __( 'Leave a Comment Translation', '__x__' );
                break;

            case 'Name' :
                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'Your Name' :
                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'Email' :
                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'Your Email' :
                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'Website' :
                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'Your Website' :
                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'Submit' :
                $translated_text = __( 'Translation here.', '__x__' );
                break;

        }

    return $translated_text;
}

If you want to do more translation, it would be best to translate the strings through the pot file. The information for the steps are in the link @Prasant shared previously.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.