Home > Enterprise >  Change language in function jQuery
Change language in function jQuery

Time:07-28

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!

CodePudding user response:

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);
    });    
}); 
  • Related