Translation of blog buttons

Hi everyone,

I’m using Polylang on my clients website. They now have a blog and want the following:

  • read more and submit button (for adding comments) are not translated into German.
  • The text for write a comment is ‘Schreibe einen kommentar’, but my client wants to change this into ‘Schreibe She einen kommentar’.

How can I do this?

For the read more button I’ve found this piece of code for the read more button on this topic on Stackoverflow:

function modify_read_more_link() {
  return  '<a href="' . get_permalink() . '">' . pll__('read more') .  '</a>';
}

add_filter( 'the_content_more_link', 'modify_read_more_link' );
pll_register_string('my-theme', 'read more');

It is showing up in the String Translations, but the translation is not working on the website. I’m sure I’m doing something wrong since I know very little JavaScript. I’m really stuck so I hope you guys can help me out.

Thank you in advance!

Kind regards,
Michelle

Hi Michelle,

Thanks for reaching out.

That may not really work that way since it should be changed through gettext hook similar to this, https://theme.co/apex/forum/t/translate-leave-a-comment/65512/4. Could you try the code mentioned there? And make sure the correct string and translation is applied.

Thanks!

Hi Rad,

Thank you for your reply!

It has worked for the read more and submit button. Unfortunately it hasn’t worked yet for Leave a Comment. It hasn’t added the “Sie”. Are there other methods to change this text?

Best regards,
Michelle

Hello Michelle,

Thanks for updating the thread. :slight_smile:

Please try out the solution shared over here and let us know the outcome:

In case it’s still not working please share website details in secure note for us to take a closer look.

Thanks.

Hi Prasant,

It’s only working partly. In the breadcrumb on the blogpost it’s displaying correctly. However, below the “Sie” is still missing.

I’ll add my login details.

Thanks in advance!

Hey Michelle,

What the Login URL? Please also give us FTP access because it’s risky testing code using the Theme Editor.

Thanks.

Sorry, completely forgot to add the login url. I’ve added the url and the login for the FTP in the secure note

Hello Michelle,

I had to update your code into this:

add_filter( 'gettext', 'translate_my_strings', 20, 3 );

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

        switch ( $translated_text ) {

            case 'Leave a Comment' :
                $translated_text = __( 'Schreiben Sie einen Kommentar', '__x__' );
                break;

        	case 'Submit' :
               	 $translated_text = __( 'Kommentar absenden', '__x__' );
               	 break;
				
			case 'Read More' :
                $translated_text = __( 'Mehr lesen', '__x__' );
                break;

        }

    return $translated_text;
}

function comment_reform ($arg) {
  $arg['title_reply'] = __('Leave a Comment', '__x__');
  return $arg;
}
add_filter('comment_form_defaults','comment_reform');

Please check your site now.

Hello RueNel,

It’s working! Thanks a lot for all your help!

Glad it’s working now and you’re most welcome!

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