Ionic ngx translate

Hi, I am currently using ngx translate which works very well in html with “{{‘try’ | translate}}” and the file en.json “” try “:” test “” however I can not to use in the TS, for an alert!

On the doc (https://ionicframework.com/docs/developer-resources/ng2-translate/) I tried those he says all down on that but I can not … could you help me?

Thanks youCapture

constructor(translate: TranslateService) {
}

showTest() {
    let myTitle: string = this.translate.instant('try'); // try = your key 
   
    let confirm: this.alertCtrl.create({
              title: myTitle,
              ...
1 Like

Thanks for your help ! “Property ‘translate’ does not exist on type ‘TryPage’”
Capture

That works for me:
Page.ts
import { TranslateService } from ‘@ngx-translate/core’;

test= ‘’;
constructor(private translate: TranslateService) {
this.translate.get(‘test’).subscribe((result) => {
this.test = result;
});
}

Page.module
import { TranslateModule } from ‘@ngx-translate/core’;

imports: [

TranslateModule

1 Like

Did you declare it in your constructor? Don’t forget the import too

import { TranslateService } from '@ngx-translate/core';

constructor(translate: TranslateService) {
}
1 Like

Yeah i did but still this error …

I get the error … but the alert is not in the constructor

Maybe a keyword like private is missing?

Full answer:

import { TranslateService } from '@ngx-translate/core';
  
constructor(private translate: TranslateService) {
}

showTest() {
  let myTitle: string = this.translate.instant('try'); // try = your key 

  let confirm: this.alertCtrl.create({
          title: myTitle,
          ...
1 Like

Yeeees! it works ! thank you very much it’s nice!

1 Like

Cool cool cool :slight_smile: