How can I include a translated string in Javascript in a .html.slim file? I am trying to create a animated notification message that initially says "Your download is being prepared" that slides into view, waits until the download is prepared, then slides out of view, where the message then changes to "Your download is ready" and slides back into view.
Here is my code:
= t 'download_preparing_msg'
javascript:
$(function() {
$('.download-status').removeClass('slide-in').addClass('slide-out')
setTimeout(function () {
$('.download-status').html(t '.download_finished_msg').removeClass('slide-out').addClass('slide-in');
}, 3000);
});
I am struggling to figure out how I can include the translated string t '.download_finished_msg' in the correct syntax for Javascript. Any suggestions?
Use interpolation #{} and escape_javascript aka j to escape quotes:
javascript:
console.log("#{ j t('.download_finished_msg') }");