BabyDriver
BabyDriver

Reputation: 181

Angular Translate a number in ngx-translate in i18n

I'm trying to translate a number in i18n json file

"category":[{"1":"home"},{"2":"search"},{"3":"account"}]

and for *ngFor

<div *ngFor="let post of posts">
    {{ post.category | translate }}
</div>

but the number is cannot translate to its value the category value return a number 1,2,3 I need to translate this result to a value from the json file

Upvotes: 1

Views: 482

Answers (1)

Rafi Henig
Rafi Henig

Reputation: 6424

Consider the following approach:

"category":{
  "1":"home",
  "2":"search",
  "3":"account"
 }

Template:

<div *ngFor="let post of posts">
  {{ "category." + post.category | translate}}
</div>

Upvotes: 1

Related Questions