diff --git a/CHANGELOG.md b/CHANGELOG.md index e98abd35e4..138ddc6c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed the duplicate data point of today in the chart of the holding detail dialog +- Fixed the missing localization of the range label in the paginator ## 3.100.0 - 2026-11-15 diff --git a/apps/client/src/app/adapter/custom-paginator-intl.ts b/apps/client/src/app/adapter/custom-paginator-intl.ts new file mode 100644 index 0000000000..8bfd139420 --- /dev/null +++ b/apps/client/src/app/adapter/custom-paginator-intl.ts @@ -0,0 +1,44 @@ +import { getLocale } from '@ghostfolio/common/helper'; + +import { Service } from '@angular/core'; +import { MatPaginatorIntl } from '@angular/material/paginator'; + +@Service() +export class CustomPaginatorIntl extends MatPaginatorIntl { + private locale = getLocale(); + + /** + * Formats the range label with the number format of the locale + */ + public override getRangeLabel = ( + page: number, + pageSize: number, + length: number + ) => { + let range = this.formatNumber(0); + + if (length > 0 && pageSize > 0) { + const startIndex = page * pageSize; + + const endIndex = + startIndex < length + ? Math.min(startIndex + pageSize, length) + : startIndex + pageSize; + + range = `${this.formatNumber(startIndex + 1)} – ${this.formatNumber(endIndex)}`; + } + + const total = this.formatNumber(Math.max(length, 0)); + + return `${range} ${$localize`of`} ${total}`; + }; + + public setLocale(aLocale: string) { + this.locale = aLocale; + this.changes.next(); + } + + private formatNumber(aNumber: number) { + return aNumber.toLocaleString(this.locale, { useGrouping: true }); + } +} diff --git a/apps/client/src/app/app.component.ts b/apps/client/src/app/app.component.ts index bd9dece2f3..d5009a8120 100644 --- a/apps/client/src/app/app.component.ts +++ b/apps/client/src/app/app.component.ts @@ -42,6 +42,7 @@ import { openOutline } from 'ionicons/icons'; import { DeviceDetectorService } from 'ngx-device-detector'; import { distinctUntilChanged, filter, map } from 'rxjs/operators'; +import { CustomPaginatorIntl } from './adapter/custom-paginator-intl'; import { GfFooterComponent } from './components/footer/footer.component'; import { GfHeaderComponent } from './components/header/header.component'; import { GfHoldingDetailDialogComponent } from './components/holding-detail-dialog/holding-detail-dialog.component'; @@ -85,6 +86,7 @@ export class GfAppComponent implements OnInit { ImpersonationStorageService ); private readonly notificationService = inject(NotificationService); + private readonly paginatorIntl = inject(CustomPaginatorIntl); private readonly route = inject(ActivatedRoute); private readonly router = inject(Router); private readonly title = inject(Title); @@ -225,6 +227,7 @@ export class GfAppComponent implements OnInit { .subscribe((locale) => { if (locale) { this.dateAdapter.setLocale(locale); + this.paginatorIntl.setLocale(locale); } }); diff --git a/apps/client/src/main.ts b/apps/client/src/main.ts index 159c2a7c98..b27eeb2e2d 100644 --- a/apps/client/src/main.ts +++ b/apps/client/src/main.ts @@ -18,6 +18,7 @@ import { MAT_DATE_FORMATS, MatNativeDateModule } from '@angular/material/core'; +import { MatPaginatorIntl } from '@angular/material/paginator'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatTooltipModule } from '@angular/material/tooltip'; import { bootstrapApplication } from '@angular/platform-browser'; @@ -28,6 +29,7 @@ import { provideMarkdown } from 'ngx-markdown'; import { provideNgxSkeletonLoader } from 'ngx-skeleton-loader'; import { CustomDateAdapter } from './app/adapter/custom-date-adapter'; +import { CustomPaginatorIntl } from './app/adapter/custom-paginator-intl'; import { DateFormats } from './app/adapter/date-formats'; import { GfAppComponent } from './app/app.component'; import { routes } from './app/app.routes'; @@ -93,6 +95,10 @@ import { environment } from './environments/environment'; provide: MAT_DATE_FORMATS, useValue: DateFormats }, + { + provide: MatPaginatorIntl, + useExisting: CustomPaginatorIntl + }, { provide: TitleStrategy, useClass: PageTitleStrategy