0

I am trying to implement the i18n in my application using json file for language translation. I am able to successfully translate for static text. but i cant able to translate for dynamic text and text that are display in array using *ngFor loops. Ex: i am displaying some set of list in dashboard through *ngFor using an array

let tempIcons = [{
id: 1,
name: test,
iconName: resultset,
iconDesc: usesd in home page
},
{
id: 2,
name: test12,
iconName: resultset23,
iconDesc: usesd in contact page
},
{
id: 3,
name: test23,
iconName: resultset23,
iconDesc: usesd in about us page
}]

Also i want to change language for dynamic text that i am getting from api service from backend. Can anyone give me the example for those scenarios.

I am using Angular 8 with i18n.

Thanks in advance

Prabakaran V
  • 233
  • 4
  • 16

1 Answers1

0

Use it like:

<div *ngFor="let item of tempIcons">
   {{'TRANSLATEPATH.' + item.name.toUpperCase() | translate}} 
</div>

Zach
  • 36
  • 8
  • Thanks for the response @zach what you mean by 'TRANSLATEPATH'. How I want to declare the json for this array in language json – Prabakaran V Apr 11 '21 at 05:51
  • Do you use `ngx-translate` with json translate files for each languages or you get the translate from your DB ? – Zach Apr 11 '21 at 09:37
  • I am not using ngx-translate I am using angular i18j directly with json translation file – Prabakaran V Apr 11 '21 at 15:55