Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng2-translate requires re-initialization inside modal #9801

Closed
vanjiminster opened this issue Dec 27, 2016 · 2 comments
Closed

ng2-translate requires re-initialization inside modal #9801

vanjiminster opened this issue Dec 27, 2016 · 2 comments

Comments

@vanjiminster
Copy link

Ionic version: (check one with "x")
[ ] 1.x
[x] 2.x

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
I'm using ng2-translate, with a set up exactly as described here: https://ionicframework.com/docs/v2/resources/ng2-translate/

Things work on pages, but do not work inside modals. It's as if the translate service is not available inside the modal. If, inside the modal, I re-initialize the translate service by running this.translate.use('fr'); then things work fine. The following code, for example, works fine.

import { TranslateService } from 'ng2-translate/ng2-translate';

@Component({
  templateUrl: 'my-modal.html',
  selector: 'my-modal',
})

export class MyModal {
constructor(
    private translate: TranslateService
  ) {
    var self = this;
    this.translate.use('fr');  // Re-initializing the translate service inside a modal
    // Here on translation works fine
  }
}

Expected behavior:
I should not need to re-initialize the translate service inside my modal. I should only need to initialize it once inside app.component.ts.

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

$ ionic info
--------------------------------
--------------------------------

Your system information:

Cordova CLI: 6.3.1
Gulp version:  CLI version 3.9.1
Gulp local:
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.1
Ionic App Lib Version: 2.1.1
Ionic App Scripts Version: 0.0.36
OS:
Node Version: v6.3.1


--------------------------------

Here are some relevant lines from my package.json

  "dependencies": {
    "@angular/common": "2.1.0",
    "@angular/compiler": "2.1.0",
    "@angular/compiler-cli": "0.6.2",
    "@angular/core": "2.1.0",
    "@angular/forms": "2.1.0",
    "@angular/http": "2.1.0",
    "@angular/platform-browser": "2.1.0",
    "@angular/platform-browser-dynamic": "2.1.0",
    "@angular/platform-server": "2.1.0",
    "@ionic/cloud-angular": "^0.7.0",
    "@ionic/storage": "^1.0.3",
    "@types/raven-js": "0.0.17",
    "ionic-angular": "^2.0.0-rc.2-201611100035",
    "ionic-native": "2.2.3",
    "ionicons": "^3.0.0",
    "moment": "^2.15.1",
    "ng2-translate": "^4.2.0",
    "raven-js": "^3.7.0",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "^0.6.21"
  },
  "devDependencies": {
    "@ionic/app-scripts": "0.0.36",
    "typescript": "^2.0.3"
  }
@jgw96 jgw96 added the v2 label Dec 27, 2016
@MagnarAr
Copy link

MagnarAr commented Feb 5, 2017

I was experiencing the same problem, but got it fixed after adding the TranslateService to providers array.

Try adding to @NgModule providers array TranslateService:

@NgModule {
    ....,
    providers: [..., TranslateService]
}
export class AppModule{}

After doing this, localization is working just fine in modals also.

@ionitron-bot
Copy link

ionitron-bot bot commented Mar 26, 2018

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Thank you for using Ionic!

@ionitron-bot ionitron-bot bot closed this as completed Mar 26, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Mar 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants