Using variables with translate filter in AngularJs

Viewed 2448

I am working on an AngularJs project and I am using the translate filter the following way:

<h2>{{'This is my text' | translate}}</h2>

It works fine, but I would like to be able to use variables in my translations. Here is what I have tried:

In the controller:

vm.text = "This {{toReplace}} is a variable.";
vm.myVariable = "random value";

In the html:

<h2>{{vm.text | translate:'{ toReplace: vm.myVariable }'}}</h2>

It doesn't replace {{toReplace}} with the content of myVariable. Instead, the page displays "This {{toReplace}} is a variable."

What should I do to make this work ?

3 Answers
Related