I use angular-cli in my project with @ngx-translate. The application has lazy-loaded modules and one shared-module (not lazy-loaded) with components. The language files are separated per modules. The problem is when I use a shared component in a lazy loaded component, the shared component get strings from the translation file of the lazy loaded module (feature.xx.json), and not from app module (core.xx.json). So I should declare the strings of shared components in translation files of every feature modules.
I would like that, the shared module use always the translation file of the app module (core.xx.json) or an own.
app.module.ts
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/core.','.json');
}
...
imports [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
},
isolate: false
}),
...
]
shared.module.ts
imports: [
TranslateModule,
...]
feature modules
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/feature.', '.json');
}
...
imports: [
...
SharedModule,
TranslateModule.forChild({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
},
isolate: true
})]