Translation inside feature modules
See original GitHub issueSo I’m trying to make the translation to work globally, but I don’t seem to get how it works. It might be my lack of understanding of how modules/services in Angular 2 work. Following the guide here I have the following setup right now:
bootstrap: [AppComponent],
declarations: [
AppComponent,
HomeComponent
],
imports: [
LocaleModule.forRoot(), // New instance of LocaleService.
LocalizationModule.forRoot(), // New instance of LocalizationService.
CoreModule,
CoursesModule
....
],
})
export class AppModule {}
And my AppComponent:
@Component({
selector: 'app',
encapsulation: ViewEncapsulation.None,
styleUrls: ['./app.component.scss'],
templateUrl: './app.component.html'
})
export class AppComponent extends Locale implements OnInit {
constructor(
public appState: AppState,
public locale: LocaleService,
public localization: LocalizationService
) {
super(locale, localization);
this.locale.addLanguages(['en', 'es']);
this.locale.definePreferredLocale('en', 'US', 30);
this.locale.definePreferredCurrency('USD');
this.localization.translationProvider('/locale/locale-');
this.localization.updateTranslation();
}
}
And then in my CoursesComponent, I have set it as the guide for Lazy routing:
@NgModule({
imports: [
...
LocaleModule, // LocaleService is singleton.
LocalizationModule.forChild() // New instance of LocalizationService.
],
declarations: [CoursesComponent]
})
The translation works in my HomeComponent, but not in my CoursesComponent. What’s weird is that if I import LocalizationModule only and not LocalizationModule.forChild(), translation works. Does that mean that it is creating an instance for the first time and the instance created from AppModule is not injected inside CoursesModule? Do I need to export the service through the CoreModule? I’m confused, any help is appreciated!
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
@Shiroh1ge I’m closing this issue. If you need, open a new issue. Greetings
You’ll never know until you try… 😃