Search code examples
angularionic2

Ionic/Angular translation of a boolean string


I would like to translate following string:

{{order.shipped?'Shipped':'No Shipped'}}

So what I did is I added | translate:

{{order.shipped?'Shipped':'No Shipped' | translate}}

In the json language file I tried to translate the whole string so:

 "order.shipped?'Shipped':'No Shipped'":"order.shipped?'geschlossen':'offen'"

But also only the part with 'Shipped':'No Shipped'. However, both alternatives are not working. So I tried to translate both strings seperately:

{{order.shipped?'{{'Shipped' | translate}}':'No Shipped'}}

I tried also alternatives with ' or " or enclosed like '". Do you know how I can translate this whole string?


Solution

  • How about a function?

    orderFunc(order){
      return order.shipped?'Shipped':'No Shipped';
    }
    ...
    {{orderFunc(order) | translate}}