2

I'm a bit new to all coding, and I want to ask for some help, please! I have this code:

$(document).ready(function() {
    $('#loadMore').click(function() {
        $('#loadMore').html('No More Post');
    });    
}); 

How can set it in different languages? For example, I'm using WordPress and WPML plugins to show some parts of blocks for different languages and it looks like this

<?php elseif($my_current_lang_hf=='pt-pt') : ?>
<div> some code here in Polish</div>
<?php else : ?>
<div> some code in English </div>

Is there something alike for jQuery? Cuz I need this No More Posts to be translated Thank you in advance!

Tanya Nami
  • 66
  • 8

1 Answers1

2

You should use the __() function for translating instead of using if lang etc. Read more about this function here: https://developer.wordpress.org/reference/functions/__/

You could declare a javascript variable like:

var no_more_posts = '<?=__('No more posts!', 'your-plugin')?>';

And your javascript code should look like this:

$(document).ready(function() {
    $('#loadMore').click(function() {
        $('#loadMore').html(no_more_posts);
    });    
}); 
Valeriu Ciuca
  • 2,084
  • 11
  • 14
  • Thank you Valeriu! I think I understand, so basically, this function registers this part as a string which I can translate for example in WPLM plugin? And 'your-plugin' what should be there if for example, I'm not using a plugin for this Load More button? – Tanya Nami Jul 27 '22 at 14:18
  • 1
    Exactly Tanya! The first argument in the function becomes the key to be translated in other languages by WPML or you can use an external editor for .po files like Poedit. 'your-plugin' is optional, if you don't put a second argument it will be set automatically to 'default'. – Valeriu Ciuca Jul 27 '22 at 15:31