How to change the language at runtime
ThomasCybulski opened this issue · 3 comments
Hey, I'm doing a bit research and I want to change the language of my project at runtime. I've tried the following code of the readme:
{
provide: TRANSLATIONS,
useFactory: (locale) => {
locale = locale || 'de-DE';
return require(`raw-loader!../assets/i18n/messages.${locale}.xlf`);
},
deps: [LOCALE_ID]
},
In my translate service is a function, to change the language, but without an effect.
setEnLanguage() {
registerLocaleData(localeEn);
}
I'm thankful for any help!
Have a look at what I did:
angular/angular#24549 (comment)
It works, only issue I have is the the require doesn't survive the build process when I use --prod
in the CLI. Havent found a solution yet.
Thanks for your answer!
The solution looks a bit hackish, I think for now, I have to wait for Angular 7.x.
@ThomasCybulski It is not that hackish mate. It loads the XLF before it bootstraps your angular app.
I asked the Angular team and they said that for now this is the best way to move forward.
Up to you.