angularionic-frameworkinternationalizationconditional-operatorangular-i18n

How to write i18n for ternary expression in Angular


I need to internationalize a ternary expression with i18n in Angular. How to do this?

<ion-title i18n>{{currentStep === 0 ? 'New chat' : 'New room'}}</ion-title>

Solution

  • Ok, I got it. We can rewrite this expression in non-ternary and apply i18n directive.

    <ion-title>
      <ng-container *ngIf="currentStep === 0; else newRoom" i18n="@@newChat">New chat</ng-container>
      <ng-template #newRoom i18n="@@newRoom">New room</ng-template>
    </ion-title>