How to translate inside ts instead in template using ngx-translate?

Hi everyone,

I’ve set up everything following this: https://github.com/ngx-translate/core

And it’s working properly when it comes to translate in templates, but inside my providers I’ve got a loader that are shown meanwhile data comes from an API Rest.

These loaders also contain an string like “Loading…”, so I need to translate them as well but I couldn’t find how to do it.

imports...

@Injectable()
export class ContenidosService {

  data:any;
  path:string;
  loader:any = null;

  constructor(public http: Http, public navCtrl: NavController, public loadingController: LoadingController) {
    
    let loader = this.loadingController.create({
      content: "Loading..."
    });  
    loader.present();
    this.loader = loader;
  }

Any help would be appreciated.
Cheers.

Here you can read all about ngx-translate and Ionic: https://ionicframework.com/docs/resources/ng2-translate/

@LoLStats I’ve been looking for any help overthere but I didn’t find anything related with my doubt.

What you have to do is this

translateService.get('LOADING_CONTENT').subscribe(
  value => {
    // value is our translated string
    let loadingContent = value; 
// Open your loading controller here and the value is your text you want to display
  }
)

Thank you so much @LoLStats, I was trying to use translatePipe.transform but I guess this way is better.

1 Like