Append translated HTML with Javascript in Blade Laravel 8

  javascript, jquery, laravel, laravel-blade

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…


Source: Laravel

Leave a Reply