How to handle translation for texts inside a .js of a WP theme

I have a wordpress application and usually I use the PHP function when I need to echo something that needs to be translated. But, right now I am implementing a new feature and in my .js file I have something like

var confirmation = confirm("Are you sure you want to quit"); 
if(confirm){
 ... 
}

The problem with the above code is that I can’t use the PHP function _e() to translate it since this a JS script.

Is there anyway to enable translation for texts echoed in JS?

Read more here: How to handle translation for texts inside a .js of a WP theme

Leave a Reply

Your email address will not be published. Required fields are marked *