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(aggregation): add translate for claims count #1121

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions projects/admin/src/app/service/bucket-name.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2021-2023 RERO
* Copyright (C) 2021-2024 RERO
* Copyright (C) 2021-2023 UCLouvain
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -51,7 +51,9 @@ describe('BucketNameService', () => {
translateService.setTranslation('en', {
bar: 'foo bar',
lang_fre: 'french',
'Organisation name': 'Organisation name translated'
'Organisation name': 'Organisation name translated',
'{{count}} claim': '{{count}} claim',
'{{count}} claims': '{{count}} claims',
});
});

Expand All @@ -71,9 +73,18 @@ describe('BucketNameService', () => {
});
});

it('should return the default value', () => {
it('should return the translated default value', () => {
service.transform('foo', 'bar').subscribe((name: string) => {
expect(name).toEqual('bar');
expect(name).toEqual('foo bar');
});
});

it('should return label for claims', () => {
service.transform('claims_count', '1').subscribe((name: string) => {
expect(name).toEqual('1 claim');
});
service.transform('claims_count', '2').subscribe((name: string) => {
expect(name).toEqual('2 claims');
});
})
});
8 changes: 6 additions & 2 deletions projects/admin/src/app/service/bucket-name.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2021-2023 RERO
* Copyright (C) 2021-2024 RERO
* Copyright (C) 2021-2023 UCLouvain
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Injectable } from '@angular/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { TranslateService } from '@ngx-translate/core';
import { IBucketNameService } from '@rero/ng-core';
import { Observable, of } from 'rxjs';
Expand Down Expand Up @@ -47,10 +48,13 @@ export class BucketNameService implements IBucketNameService {
*/
transform(aggregationKey: string, value: string): Observable<string> {
switch (aggregationKey) {
case 'claims_count':
const label = Number(value) < 2 ? _('{{count}} claim') : _('{{count}} claims');
return of(this.translateService.instant(label, { count: value }));
case 'language': return of(this.translateService.instant(`lang_${value}`));
case 'library': return this.libraryApiService.getByPid(value).pipe(map(record => record.name));
case 'organisation': return this.organisationApiService.getByPid(value).pipe(map(record => record.name));
default: return of(value);
default: return of(this.translateService.instant(value));
}
}
}
Loading