I'm trying to get translations work for both the app components and the lib components. For now I can only get app or lib components to work, but not at the same time.
Structure:
- Created an ionic app with a home component
- Created a "features/ui" lib with a login component
- Created a "core/localization" lib with a translation component (I have the translation files here and in angular.json I copy the files to the app)
I can make the home component in the app work if I add import TranslateModule and provider in the libs/features/ui/ui.module.ts:
@NgModule({
imports: [
ReactiveFormsModule,
FormsModule,
CommonModule,
ToastrModule.forRoot(),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: createTranslateLoader,
deps: [HttpClient]
}
})],
providers: [
{
provide: APP_INITIALIZER,
useFactory: appInitializerFactory,
deps: [TranslateService, Injector],
multi: true
}
],
declarations: [LoginComponent],
exports: [
LoginComponent
]
})
Now the translations for the login works, but the home component just writes out the translation key "home.greet"
I can also make the login component in the app work if I instead add the same import TranslateModule and provider in the libs/core/core.module.ts
If I add the code in the two different place at the same time, the login will only translate, but the home component again just writes out the translation key "home.greet"
Also it seems wrong to initialize it twice, so where should I put my import and provider for the translations and how should I manage to translate in both places?