Translation for instant params

Asked by At

I am using ngx-translate and have no problem with translating strings values in HTML components, but how can I translate something like this:

  <input matInput tabindex="-1" required placeholder="{{j == 0 ? ('Where') : ( j == passatControlGroup.controls.length - 1 ? 'Time' : 'Via')}}"

My translation is in JSON file and I would like to make it with key:value, as I made for HTML strings.


What is syntax to translate ('Where'), if I want to wirte it to JSON file as:

"passatCarComponent": "translation for Where"

Thank you

1 Answers

Daniel W Strimpel On Best Solutions

If you are wanting to translate the Where, Time, and Via text in your placeholder attribute, you'll need to:

  • change the text to the name of the key for the translation
  • add those keys and translations to your translation file
  • add the translate pipe in your placeholder attribute {{ ... }} logic

Your template would look something like this:

<input matInput tabindex="-1" required placeholder="{{ (j == 0 ? ('passatCarComponent.Where') : ( j == passatControlGroup.controls.length - 1 ? 'passatCarComponent.Time' : 'passatCarComponent.Via')) | translate }}">