0

Stuck while translating a html text using ngx-translate. I am getting missing language key error. I have correctly imported the ngx-translation module into this component's module. I am confused on why the translation is working

[infoText]="invalidCredentials ? 'Username Incorrect' : ''"

I tried translating like this.

[infoText]=" (invalidCredentials ? 'login.username-incorrect' : '') | translate"
[infoText]="invalidCredentials ? ('login.username-incorrect' | translate) : '' "

None of this works. Anybody know why?

When I tried like this it works. So can't we translate or ignore empty strings?

[infoText]=" (invalidCredentials ? 'login.username-incorrect' : 'login.password-incorrect') | translate"
Chris Barr
  • 29,851
  • 23
  • 95
  • 135

1 Answers1

0

I hope this will help. I will give an example that works for me:

In the ts file I have:

 constructor(public translate: TranslateService) {...}

 public c1="";
 public c2="";
 public condition =true;

 onchange(ev)
  {   
   this.translate.use('en');
   this.translate.get("<KEY1>").subscribe(x=>this.c1=x);
   this.translate.get("<KEY2>").subscribe(x=>this.c2=x);
  }

and in the HTML template I do something like this:

 [value]="condition ? c1: c2" 
D A
  • 1,724
  • 1
  • 8
  • 19