Passing a JS var from AJAX response to Twig

I am trying to pass a Javascript var = value that I receive from an Ajax response to the twig |trans filter so I can translate the strings.

{{('' ~ value)|trans}} doesn't work, because value returns empty.

  $.each( tipi_nepremicnin, function( key, value ) {
    "<option value='" + value + "'>" 
    + '{{('' ~ value)|trans}}'  
    + "</option>").removeAttr("disabled"


You can't do that.

You've got two solutions :

  1. Translate your content in PHP then pass it to ajax response
  2. Use Bazing js translation bundle so you can translate JS variables
js interview questions