Open ThomasBoersma opened 4 years ago
This was already discussed in a previous issue on the startkit repo: https://github.com/ngx-rocket/starter-kit/issues/16
Basically, LOCALE_ID
can only be set once during app startup and do not support dynamic language changes, as it's meant for static language setup, there's nothing we can really do about it.
If you want to use the built-in pipes the best solution is to make simple wrappers like this one:
@Pipe({name: 'dynamicDate', pure: true})
export class DynamicDatePipe implements PipeTransform {
constructor(private datePipe: DatePipe, private i18n: I18nService) {}
transform(value: any): string|null {
return this.datePipe.transform(value, undefined, undefined, this.i18n.language);
}
}
I'm submitting a...
Current behavior
The angular pipes (like
| date
) in combination with the translations don't work as expected. When the current language is fr-FR you would expect a day name in French. But when I reload the app the name of the day is still in English.Expected behavior
The name of the day should be in French.
Minimal reproduction of the problem with instructions
I used the out-of-the-box example of the generator-ngx-rocket repo.
My proposal
When you register the Angular common locales (Fr, En, De etc) and initialise the i18nService in the app.module file (for the latter instead of app.compoment file). You can set the
LOCALE_ID
with a factory like approach.In app.module.ts
Is this a better approach? I am really interested how you do it with dynamic/language dependent pipes.