How do I translate added slider button?

I tried adding the JS snippet for adding a second slider button (from the “Code snippets” section: http://docs.athemes.com/article/49-add-a-second-slider-button).

The button works fine, but Polylang (my translation plugin) doesn’t recognize the new button for translation.

  • How do I add the new button as a string in Polylang?

Btw this is the JS snippet:

jQuery(function($) {
       var myButton = '<a href="http://example.org" class="roll-button button-slider">My Button</a>';
       $( '.slide-inner' ).append(myButton);
});

And here is my test page: blog.cbmtranslate.dk

Hello there,

Since the new button was made with jQuery code, the Polylang plugin can’t recognize it. You should do manual translation with jQuery code to manipulate the button depending on the current language code attributed to the HTML tag. Replace your code with this one:


jQuery(function($) {

  if( $( '.slide-inner' ).length ) {

    var lang    = $('html').attr('lang');

    // Default button 
    var btnLink = 'http://example.org';
    var btnText = 'My Button';

    if( lang == 'da-DK' ) {
      btnLink = 'http://example.org/da';
      btnText = 'Translated Button';      
    }  
  
    var myButton = '<a href="'+btnLink+'" class="roll-button button-slider">'+btnText+'</a>';
    $( '.slide-inner' ).append(myButton);
  }

});

The translation is done within this code block:


if( lang == 'da-DK' ) {
  btnLink = 'http://example.org/da';
  btnText = 'Translated Button';      
}  

If you have other language, you should duplicate it and use the correct language code.

Regards,
Kharis

Thank you, Kharis!

Worked like a charm.

Best,

Christian.

You’re welcome, Christian!

Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

Regards,
Kharis