Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
How can I include a translated string in Javascript for my Rails application?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use interpolation #{} and escape_javascript aka j to escape quotes:

javascript:
  console.log("#{ j t('.download_finished_msg') }");

https://rdoc.info/gems/slim/frames#text-interpolation

https://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-escape_javascript

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!