6

Is it possible to use i18n on strings that require conditional operation

<h2 i18n>{{ updateMode ? 'Edit' : 'Add'}}</h2>
Daniel W Strimpel
  • 8,190
  • 2
  • 28
  • 38
tonis
  • 95
  • 1
  • 5
  • Have you tried it out? I mean if you already use angulars i18n mechanism, then you probably can test this in 1 minute. (I use ngx-translate instead, so I cannot answer your question). – tom van green May 02 '18 at 07:12

1 Answers1

4
<h2 i18n>{{ updateMode ? 'Edit' : 'Add'}}</h2>

In your .xlf file you will get something like this

<source>
  <x id="INTERPOLATION" equiv-text="{{updateMode  ? 'Edit': 'Add'}}"/>
</source>

Target should look like this:

<target>
  {{updateMode  ? 'TranslatedValue1' : 'TranslatedValue2'}}
</target>

EDIT: This answer is not relevant since angular v.9.0 You can not use ternary operator anymore, instead it use:

<ng-container *ngIf="updateMode" i18n="@@translationID1>TranslatedValue1</ng-container>
<ng-container *ngIf="!updateMode" i18n="@@translationID2>TranslatedValue2</ng-container>
Titania
  • 74
  • 4