Skip to content

Commit

Permalink
fix(aggregation): add translate for claims count
Browse files Browse the repository at this point in the history
Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Feb 21, 2024
1 parent 20bb625 commit 84d2b94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
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));
}
}
}

0 comments on commit 84d2b94

Please sign in to comment.