Change back button label by language


#1

In my ionic app I have menu with back-button.
The text of back button is configured by IonicModule.forRoot:

 imports: [
IonicModule.forRoot(MyApp,{
    backButtonIcon: 'arrow-forward',
    backButtonText: 'back',
    tabsPlacement: 'top',
    //etc...
  })]

At my app I have button for change language and I want to translate the back-button according to the selected language.
But how can I have access for app configuration in simple function at any angular-2 component?


#2

I think those setting are at the module level so every page in your app will have the same value of back button, since the module has access to all the components and services - see if you can set the language value in a service variable and try to see it on the module as

backButtonText: ServiceName.staticLanguageProperty

I havent tried it but you can give it a try.

Let us know if it works.


#3

You can use the ViewController to change the back button text.

Be sure to insert the call in ionViewWillEnter or later.

ionViewWillEnter() {
  this.translateService.get('Back').subscribe(text => {
    this.viewController.setBackButtonText(text);
  });
}

http://ionicframework.com/docs/v2/api/navigation/ViewController/#setBackButtonText