Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda