I am using Electron 10 and Angular 10 and also use ngx-translate. I would like to update the translations of the current view/page after the user switched the language in a dropdown menu.
During development I use of course Angular with its HTTP server, that's why I use HttpLoaderFactory. But for production builds I use the custom translateFactory which loads the JSON files via TranslateUniversalLoader. Is this ok to do?
Neither in development nor production builds I can make the strings update without restarting the app. I have a dropdown menu and on change I simply call this.translate.use(lang). Is the view supposed to be reloaded? What is the expected behaviour here?
I register the module as follows:
export class TranslateUniversalLoader implements TranslateLoader {
constructor() {
}
public getTranslation(lang: string): Observable<any> {
return of(TRANSLATIONS[lang]);
}
}
export function translateFactory() {
return new TranslateUniversalLoader();
}
}
...
@NgModule({
declarations: [AppComponent],
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: isProductionBuild() ? translateFactory : HttpLoaderFactory,
deps: [HttpClient]
},
isolate : false
})