I'm looking for a way to
How can this be set dynamically in angular2 + typescript ?
Here is my attempt from the official Angular2 plunkr : https://plnkr.co/edit/lWV4VhzpWYnCXeDBpzsn?p=preview where I've commented out the
document.locale='en';
and tried to retrieve the window.document inside a typescript service, and change the locale there, but despite it is called and the locale set properly (seen in the console), the interface is not displayed in the chosen language at startup.
Then of course the dropdown buttons don't work either because the same erroneous way is used and the display is not refreshed but that is the next step.
I am saving user selected language key into local storage:
//<select name="selectLocate" (change)="onChange($event.target.value)">
public onChange(localeId: string): void {
localStorage.setItem('localeId', localeId);
location.reload(true);
}
Then force reloading, and in i18n.provider.ts
let locale = localStorage.getItem('localeId');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With