diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html index 440e1ddee3..d34373ba16 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html @@ -45,10 +45,14 @@ {{ metadata.recordUpdated && metadata.recordUpdated.toLocaleString() }}

-
+

record.metadata.updateFrequency

-

- domain.record.updateFrequency.{{ metadata.updateFrequency }} +

+ {{ updateFrequency }}

diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts index eaba09c8d0..eb1bc28a3a 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts @@ -4,6 +4,8 @@ import { TranslateModule } from '@ngx-translate/core' import { ContentGhostComponent } from '../content-ghost/content-ghost.component' import { MetadataInfoComponent } from './metadata-info.component' import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures' +import { TranslateTestingModule } from '@geonetwork-ui/util/i18n' +import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler' describe('MetadataInfoComponent', () => { let component: MetadataInfoComponent @@ -11,7 +13,19 @@ describe('MetadataInfoComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), UtilSharedModule], + imports: [ + TranslateModule.forRoot(), + UtilSharedModule, + TranslateTestingModule.withTranslations({ + en: { + 'domain.record.updateFrequency.notPlanned': 'Not planned', + 'domain.record.updateFrequency.month': + '{count, plural, =0{0 times} one{once} other{{count} times}} per month', + }, + }) + .withDefaultLanguage('en') + .withCompiler(new TranslateMessageFormatCompiler()), + ], declarations: [MetadataInfoComponent, ContentGhostComponent], }).compileComponents() }) @@ -73,4 +87,35 @@ describe('MetadataInfoComponent', () => { expect(displayedElement).toBeTruthy() }) }) + describe('updateFrequency', () => { + describe('updateFrequency as UpdateFrequencyCode', () => { + beforeEach(() => { + fixture = TestBed.createComponent(MetadataInfoComponent) + component = fixture.componentInstance + component.metadata = { + ...DATASET_RECORDS[0], + updateFrequency: 'notPlanned', + } + fixture.detectChanges() + }) + it('should display the updateFrequency code correctly', () => { + const displayedElement = + fixture.nativeElement.querySelector('.updateFrequency') + expect(displayedElement.textContent).toEqual(' Not planned ') + }) + }) + describe('updateFrequency as UpdateFrequencyCustom', () => { + beforeEach(() => { + fixture = TestBed.createComponent(MetadataInfoComponent) + component = fixture.componentInstance + component.metadata = DATASET_RECORDS[0] + fixture.detectChanges() + }) + it('should display the updateFrequency object correctly', () => { + const displayedElement = + fixture.nativeElement.querySelector('.updateFrequency') + expect(displayedElement.textContent).toEqual(' 3 times per month ') + }) + }) + }) }) diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts index 98bcb397db..18b1990b20 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts @@ -17,6 +17,7 @@ export class MetadataInfoComponent { @Input() metadata: Partial @Input() incomplete: boolean @Output() keyword = new EventEmitter() + updatedTimes: number get hasUsage() { return ( @@ -37,6 +38,15 @@ export class MetadataInfoComponent { return array } + get updateFrequency(): string { + if (this.metadata.updateFrequency instanceof Object) { + this.updatedTimes = this.metadata.updateFrequency.updatedTimes + return `domain.record.updateFrequency.${this.metadata.updateFrequency.per}` + } else { + return `domain.record.updateFrequency.${this.metadata.updateFrequency}` + } + } + fieldReady(propName: string) { return !this.incomplete || propName in this.metadata } diff --git a/translations/de.json b/translations/de.json index d4da8d0e2c..2752fc9fc9 100644 --- a/translations/de.json +++ b/translations/de.json @@ -121,14 +121,14 @@ "domain.record.status.under_development": "In Erstellung", "domain.record.updateFrequency.asNeeded": "Bei Bedarf", "domain.record.updateFrequency.continual": "Kontinuierlich", - "domain.record.updateFrequency.day": "Tag", + "domain.record.updateFrequency.day": "{count, plural, =0{0} one{Ein} other{{count}}} mal am Tag", "domain.record.updateFrequency.irregular": "Unregelmässig", - "domain.record.updateFrequency.month": "Monat", + "domain.record.updateFrequency.month": "{count, plural, =0{0} one{Ein} other{{count}}} mal im Monat", "domain.record.updateFrequency.notPlanned": "Nicht geplant", "domain.record.updateFrequency.periodic": "Regelmässig", "domain.record.updateFrequency.unknown": "Unbekannt", - "domain.record.updateFrequency.week": "Woche", - "domain.record.updateFrequency.year": "Jahr", + "domain.record.updateFrequency.week": "{count, plural, =0{0} one{Ein} other{{count}}} mal in der Woche", + "domain.record.updateFrequency.year": "{count, plural, =0{0} one{Ein} other{{count}}} mal im Jahr", "downloads.format.unknown": "unbekannt", "downloads.wfs.featuretype.not.found": "Die Schicht wurde nicht gefunden", "dropFile": "Datei ablegen", diff --git a/translations/en.json b/translations/en.json index a5161f5937..cfd5d2ed7c 100644 --- a/translations/en.json +++ b/translations/en.json @@ -121,14 +121,14 @@ "domain.record.status.under_development": "Under development", "domain.record.updateFrequency.asNeeded": "As needed", "domain.record.updateFrequency.continual": "Continual", - "domain.record.updateFrequency.day": "day", + "domain.record.updateFrequency.day": "{count, plural, =0{0 times} one{Once} other{{count} times}} per day", "domain.record.updateFrequency.irregular": "Irregular", - "domain.record.updateFrequency.month": "month", + "domain.record.updateFrequency.month": "{count, plural, =0{0 times} one{Once} other{{count} times}} per month", "domain.record.updateFrequency.notPlanned": "Not planned", "domain.record.updateFrequency.periodic": "Periodic", "domain.record.updateFrequency.unknown": "Unknown", - "domain.record.updateFrequency.week": "week", - "domain.record.updateFrequency.year": "year", + "domain.record.updateFrequency.week": "{count, plural, =0{0 times} one{Once} other{{count} times}} per week", + "domain.record.updateFrequency.year": "{count, plural, =0{0 times} one{Once} other{{count} times}} per year", "downloads.format.unknown": "unknown", "downloads.wfs.featuretype.not.found": "The layer was not found", "dropFile": "drop file", diff --git a/translations/fr.json b/translations/fr.json index 3624304b54..7364274faf 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -121,14 +121,14 @@ "domain.record.status.under_development": "En cours de création", "domain.record.updateFrequency.asNeeded": "Lorsque nécessaire", "domain.record.updateFrequency.continual": "Continue", - "domain.record.updateFrequency.day": "jour", + "domain.record.updateFrequency.day": "{count, plural, =0{0} one{Une} other{{count}}} fois par jour", "domain.record.updateFrequency.irregular": "Irrégulière", - "domain.record.updateFrequency.month": "mois", + "domain.record.updateFrequency.month": "{count, plural, =0{0} one{Une} other{{count}}} fois par mois", "domain.record.updateFrequency.notPlanned": "Non planifiée", "domain.record.updateFrequency.periodic": "Récurrente", "domain.record.updateFrequency.unknown": "Inconnue", - "domain.record.updateFrequency.week": "semaine", - "domain.record.updateFrequency.year": "an", + "domain.record.updateFrequency.week": "{count, plural, =0{0} one{Une} other{{count}}} fois par semaine", + "domain.record.updateFrequency.year": "{count, plural, =0{0} one{Une} other{{count}}} fois par an", "downloads.format.unknown": "inconnu", "downloads.wfs.featuretype.not.found": "La couche n'a pas été retrouvée", "dropFile": "Faites glisser votre fichier",