Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Dates should be translated when switching to other languages #8469

Merged
merged 7 commits into from
Oct 23, 2024
14 changes: 13 additions & 1 deletion packages/ui-core/shared/src/lib/pipes/date-format.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Store } from '@gauzy/ui-core/core';
export class DateFormatPipe implements PipeTransform {
dateFormat: string = 'd MMMM, y';
regionCode: string = RegionsEnum.EN;
locale!: string;
samuelmbabhazi marked this conversation as resolved.
Show resolved Hide resolved

constructor(private readonly store: Store) {
this.store.selectedOrganization$
Expand All @@ -27,6 +28,17 @@ export class DateFormatPipe implements PipeTransform {
untilDestroyed(this)
)
.subscribe();

this.store.preferredLanguage$
.pipe(
distinctUntilChange(),
filter((preferredLanguage: string) => !!preferredLanguage),
tap((preferredLanguage: string) => {
this.locale = preferredLanguage;
}),
untilDestroyed(this)
)
.subscribe();
}

/**
Expand All @@ -52,7 +64,7 @@ export class DateFormatPipe implements PipeTransform {
}

if (isEmpty(locale)) {
locale = this.regionCode;
locale = this.locale;
}

if (date && defaultFormat) {
Expand Down
Loading