I have problems using ng2-translate in combination with modals in ionic2. Translations in normal pages are working.
This is my app.module.ts file:
import ...
@NgModule({
declarations: [
MyApp,
//...
],
imports: [
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
}),
IonicModule.forRoot(MyApp),
],
exports: [
TranslateModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
//...
],
providers: [Storage, {provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}
export function createTranslateLoader(http: Http) {
return new TranslateStaticLoader(http, 'assets/i18n', '.json');
}
For example in my dashboard I can use following HTML-Code and get the correct translation:
<h2>{{'general.tasks' | translate}}</h2>
But when I now open a new modal with the ModalController from ionic-angular by following code:
let taskModal = this.modalCtrl.create(TaskCancelPage, {'task': task});
taskModal.onDidDismiss(data => {
console.log(data);
});
taskModal.present();
Having the same HTML Code in that new TaskCancelPage
<h2>{{'general.tasks' | translate}}</h2>
But here I only get general.tasks instead of the translated value.
It works for me here is what I've done:
In [project]/src//app.module.ts:
In [project]/src/app/app.component.ts
in [project]/src/custom-pipe/capitalize/capitalize.ts:
in [project]/src/services/translation/translation.ts
Then in your pages (modal or not) where you want to use it import the service:
And declare the service in the constructor of the page:
In your html template call it:
or if you don't want to capitalize the first letter :
And in a page if you call an
AlertController
for example you can do -:or if you don't want to capitalize the first letter :
FOR SOME REASON IT ONLY READS THE TRAD FILES UNDER [project]/wwww/assets/i18n/[2 chars language code].json