1

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.

{{('makler.realestate::lang.tip_neprem.' ~ value)|trans}} doesn't work, because value returns empty.

  $.each( tipi_nepremicnin, function( key, value ) {
    $(select_input)
    .append(
    "<option value='" + value + "'>" 
    + '{{('makler.realestate::lang.tip_neprem.' ~ value)|trans}}'  
    + "</option>").removeAttr("disabled"
    );
  }
Svedr
  • 589
  • 2
  • 6
  • 21
  • 1
    Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Shira Jul 04 '16 at 11:11

1 Answers1

1

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
t-n-y
  • 1,201
  • 2
  • 13
  • 27