Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda