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

283
Views
Append translated HTML with Javascript in Blade Laravel 8

I want to add text with javascript or jquery and translate it automatically.

I tried for example:

let x = 'Cats';
$('#divToAppend').text(`{{ __('${x}') }}`)

When I do that, the text appends without translation.


When I write directly
{{ __('Cats') }}

in the blade file, the translation works.

Can somebody help me? I tried with the {!! __('${x}') !!}, tried with only javascript and no jQUery, but nothings changes...

Thanks!

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

0

Blade is a template engine and {{ ... }} statements are templates. When the site is loaded those templates will be evaluated on the server side to generate plain HTML which then is sent to the client. When you try to add templates using JavaScript on the client side it won't work because the server can't evaluate them.

If you want to add a translated string inside your JavaScript you have to either store all the translations in the JavaScript itself and pick the required one or send a request to the server which you let return the translated string.

You can read more about what templating is here.

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!