Angular 4 - ionic 3 text translation inside .ts' file

Hi guys, I want to know how to translate text to a .ts' file
basically it is loading text

showLoader() { 
this.loading = this.loadingCtrl.create({
  content: 'Loading...'
});
this.loading.present();

  }

what I need is the text "Loading ..." translated into "Fee ..." When the language is set to French, thanks

+4
source share
2 answers

You can do this as shown below:

Note: I extracted this from my working code base. Therefore, please configure as you wish. If you need more help, let me know.

presentLoader(): Loading {
    this.translate.get('Please_wait').subscribe(res => {
      this.content = res;
    });
    let loader = this.loadingCtrl.create({
      content: this.content
    });
    loader.present();
    return loader;
  }
+5
source

@ Sampata's answer works fine, but still I wanted to add another way to do this by returning Promise.

get , Loading, , , .

// Imports
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/toPromise';

// ...

presentLoader(translationKey: string): Promise<Loading> {
    return this.translate.get(translationKey)
            .toPromise()
            .then(translation => {

                // Create the loader
                let loader = this.loadingCtrl.create({
                    content: translation
                });

                // Present the loader
                loader.present();

                // Return the loader
                return loader;
            });
}

:

this.presentLoader('Please_wait').then((loader: Loading) => {
    // This code is executed after the loading has been presented...
    // ... You can use the loader property to hide the loader
});
+3

Source: https://habr.com/ru/post/1686118/


All Articles