Using angular i18n on conditional operators (ternary)
Asked Answered
L

1

6

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

<h2 i18n>{{ updateMode ? 'Edit' : 'Add'}}</h2>
Lomond answered 1/5, 2018 at 23:28 Comment(1)
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).Madonnamadora
C
5
<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>
Cardioid answered 9/7, 2019 at 17:16 Comment(1)
I get an error: Unable to parse ICU expression in "{{loading ? 'Loading Module...' : 'Log In'}}" message.Lauren

© 2022 - 2024 — McMap. All rights reserved.