Skip to content

Commit 5855d88

Browse files
[DSC-1669] - Improve handling of metadata group labels
1 parent 6538fd3 commit 5855d88

5 files changed

Lines changed: 257 additions & 20 deletions

File tree

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadataGroup/inline/inline.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { FieldRenderingType, MetadataBoxFieldRendering } from '../../metadata-bo
66
import { Item } from '../../../../../../../../core/shared/item.model';
77
import { LayoutField } from '../../../../../../../../core/layout/models/box.model';
88
import { MetadataGroupComponent } from '../metadata-group.component';
9+
import { TranslationUtilityService } from '../../../../../../../services/translation.service';
910

1011
/**
1112
* This component renders the inline metadata group fields
@@ -23,9 +24,10 @@ export class InlineComponent extends MetadataGroupComponent implements OnInit {
2324
@Inject('itemProvider') public itemProvider: Item,
2425
@Inject('renderingSubTypeProvider') public renderingSubTypeProvider: string,
2526
@Inject('tabNameProvider') public tabNameProvider: string,
26-
protected translateService: TranslateService
27+
protected translateService: TranslateService,
28+
protected translationUtilityService: TranslationUtilityService,
2729
) {
28-
super(fieldProvider, itemProvider, renderingSubTypeProvider, tabNameProvider, translateService);
30+
super(fieldProvider, itemProvider, renderingSubTypeProvider, tabNameProvider, translateService, translationUtilityService);
2931
}
3032

3133
}

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadataGroup/metadata-group.component.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TranslateService } from '@ngx-translate/core';
66
import { isNotEmpty } from '../../../../../../../shared/empty.util';
77
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
88
import { BehaviorSubject } from 'rxjs';
9+
import { TranslationUtilityService } from '../../../../../../services/translation.service';
910

1011

1112
export interface NestedMetadataGroupEntry {
@@ -44,7 +45,8 @@ export abstract class MetadataGroupComponent extends RenderingTypeStructuredMode
4445
@Inject('itemProvider') public itemProvider: Item,
4546
@Inject('renderingSubTypeProvider') public renderingSubTypeProvider: string,
4647
@Inject('tabNameProvider') public tabNameProvider: string,
47-
protected translateService: TranslateService
48+
protected translateService: TranslateService,
49+
protected translationUtilityService: TranslationUtilityService
4850
) {
4951
super(fieldProvider, itemProvider, renderingSubTypeProvider, tabNameProvider, translateService);
5052
}
@@ -83,14 +85,13 @@ export abstract class MetadataGroupComponent extends RenderingTypeStructuredMode
8385
* Returns a string representing the label of field if exists
8486
*/
8587
getLabel(field: LayoutField): string {
86-
const fieldLabelI18nKey = this.fieldI18nPrefix + field.label;
87-
const header: string = this.translateService.instant(fieldLabelI18nKey);
88-
if (header === fieldLabelI18nKey) {
89-
// if translation does not exist return the value present in the header property
90-
return this.translateService.instant(field.label);
91-
} else {
92-
return header;
93-
}
88+
return this.translationUtilityService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.[' + field.metadata + ']') ??
89+
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.[' + field.metadata + ']') ??
90+
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.' + field.metadata) ??
91+
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + '[' + field.metadata + ']') ??
92+
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + field.label) ??
93+
field.label ??
94+
field.metadata;
9495
}
9596

9697
ngOnDestroy(): void {

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/row/metadata-container/metadata-container.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MetadataFilter } from '../../../../../../../core/data/bitstream-data.se
1818
import { RemoteData } from '../../../../../../../core/data/remote-data';
1919
import { PaginatedList } from '../../../../../../../core/data/paginated-list.model';
2020
import { Observable } from 'rxjs';
21+
import { TranslationUtilityService } from '../../../../../../services/translation.service';
2122

2223
@Component({
2324
selector: 'ds-metadata-container',
@@ -61,7 +62,8 @@ export class MetadataContainerComponent implements OnInit {
6162
constructor(
6263
protected bitstreamDataService: BitstreamDataService,
6364
protected translateService: TranslateService,
64-
protected cd: ChangeDetectorRef
65+
protected cd: ChangeDetectorRef,
66+
protected translationService: TranslationUtilityService
6567
) {
6668
}
6769

@@ -83,14 +85,12 @@ export class MetadataContainerComponent implements OnInit {
8385
* Returns a string representing the label of field if exists
8486
*/
8587
get label(): string {
86-
const fieldLabelI18nKey = this.fieldI18nPrefix + this.item.entityType + '.' + this.field.metadata;
87-
const header: string = this.translateService.instant(fieldLabelI18nKey);
88-
if (header === fieldLabelI18nKey) {
89-
// if translation does not exist return the value present in the header property
90-
return this.translateService.instant(this.field.label);
91-
} else {
92-
return header;
93-
}
88+
return this.translationService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.[' + this.field.metadata + ']') ??
89+
this.translationService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.' + this.field.metadata) ??
90+
this.translationService.getTranslation(this.fieldI18nPrefix + '[' + this.field.metadata + ']') ??
91+
this.translationService.getTranslation(this.fieldI18nPrefix + this.field.label) ??
92+
this.field.label ??
93+
this.field.metadata;
9494
}
9595

9696
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Injectable } from '@angular/core';
2+
import { TranslateService } from '@ngx-translate/core';
3+
4+
@Injectable({
5+
providedIn: 'root'
6+
})
7+
export class TranslationUtilityService {
8+
9+
constructor(private translateService: TranslateService) {
10+
}
11+
12+
/**
13+
* Returns true if the passed value is a NgbDateStruct.
14+
*
15+
* @param fieldLabelI18nKey
16+
* The field label i18n key
17+
* @return boolean
18+
* if the translation haven't found return null otherwise return translated label
19+
*/
20+
getTranslation(fieldLabelI18nKey: string): string {
21+
const header: string = this.translateService.instant(fieldLabelI18nKey);
22+
if (header !== fieldLabelI18nKey) {
23+
return header;
24+
}
25+
return null;
26+
}
27+
}

src/assets/i18n/en.json5

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7378,4 +7378,211 @@
73787378
"form.other-information.selection.data-crispj_coinvestigator_affiliation": "Affiliation",
73797379

73807380
"form.other-information.selection.alternative-names": "Select alternative name",
7381+
7382+
// Layout - Common i18n keys: Metadata fallback values (not generated by CRIS layout tool)
7383+
7384+
7385+
// Layout - Autogenerated i18n keys: Tab headers
7386+
7387+
"layout.tab.header.Person.details": "Profile",
7388+
"layout.tab.header.Person.publications": "Publications",
7389+
"layout.tab.header.Person.projects": "Projects",
7390+
"layout.tab.header.Person.otherinfo": "Other",
7391+
"layout.tab.header.Person.indicators": "Metrics",
7392+
"layout.tab.header.Person.secure": "Secured Tab",
7393+
"layout.tab.header.OrgUnit.maininformation": "Information",
7394+
"layout.tab.header.OrgUnit.details": "Details",
7395+
"layout.tab.header.OrgUnit.organizations": "Organizations",
7396+
"layout.tab.header.OrgUnit.publications": "Publications",
7397+
"layout.tab.header.OrgUnit.rppublications": "Researchers publications",
7398+
"layout.tab.header.OrgUnit.projects": "Projects",
7399+
"layout.tab.header.OrgUnit.rpprojects": "Researchers projects",
7400+
"layout.tab.header.OrgUnit.people": "People",
7401+
"layout.tab.header.Project.details": "Details",
7402+
"layout.tab.header.Project.outputs::projectoutputs": "Outputs::Publications",
7403+
"layout.tab.header.Project.outputs::fundings": "Outputs::Fundings",
7404+
"layout.tab.header.Journal.details": "Details",
7405+
"layout.tab.header.Event.details": "Details",
7406+
"layout.tab.header.Equipment.details": "Details",
7407+
"layout.tab.header.Funding.details": "Details",
7408+
"layout.tab.header.Publication.details": "Details",
7409+
"layout.tab.header.Product.details": "Details",
7410+
"layout.tab.header.Patent.details": "Details",
7411+
7412+
// Layout - Autogenerated i18n keys: box headers
7413+
7414+
"layout.box.header.Person.projects": "Projects",
7415+
"layout.box.header.Person.researchoutputs": "Publications",
7416+
"layout.box.header.Person.qualifications": "Professional Qualifications",
7417+
"layout.box.header.Person.media": "Media Contact Directory",
7418+
"layout.box.header.Person.namecard": "Name Card",
7419+
"layout.box.header.Person.researcherprofile": "Profile",
7420+
"layout.box.header.Person.metrics": "Metrics",
7421+
"layout.box.header.Person.usagemetrics": "Usage Metrics",
7422+
"layout.box.header.Person.secure": "Secured box",
7423+
"layout.box.header.OrgUnit.rpprojects": "OrgUnit's Researchers projects",
7424+
"layout.box.header.OrgUnit.publications": "OrgUnit's Publications",
7425+
"layout.box.header.OrgUnit.rppublications": "OrgUnit's Researchers publications",
7426+
"layout.box.header.OrgUnit.people": "OrgUnit's Researchers",
7427+
"layout.box.header.OrgUnit.projects": "OrgUnit funded Projects",
7428+
"layout.box.header.OrgUnit.description": "Description",
7429+
"layout.box.header.OrgUnit.organizations": "SubOrgUnits",
7430+
"layout.box.header.OrgUnit.details": "Details",
7431+
"layout.box.header.OrgUnit.orgcard": "Card",
7432+
"layout.box.header.OrgUnit.metrics": "Metrics",
7433+
"layout.box.header.Project.description": "Description",
7434+
"layout.box.header.Project.researchoutputs": "Publications",
7435+
"layout.box.header.Project.fundings": "Fundings",
7436+
"layout.box.header.Project.primarydata": "Primary Data",
7437+
"layout.box.header.Project.projectcard": "Project Card",
7438+
"layout.box.header.Project.metrics": "Metrics",
7439+
"layout.box.header.Funding.primarydata": "Primary Data",
7440+
"layout.box.header.Funding.financialdata": "Financial Data",
7441+
"layout.box.header.Funding.metrics": "Metrics",
7442+
"layout.box.header.Journal.details": "Journal description",
7443+
"layout.box.header.Journal.metrics": "Metrics",
7444+
"layout.box.header.Event.details": "Description",
7445+
"layout.box.header.Event.metrics": "Metrics",
7446+
"layout.box.header.Equipment.details": "Equipment description",
7447+
"layout.box.header.Equipment.metrics": "Metrics",
7448+
"layout.box.header.Publication.details": "Details",
7449+
"layout.box.header.Publication.metrics": "Metrics",
7450+
"layout.box.header.Publication.altmetrics": "Alternative Metrics",
7451+
"layout.box.header.Publication.usagemetrics": "Usage Metrics",
7452+
"layout.box.header.Patent.details": "Details",
7453+
"layout.box.header.Patent.metrics": "Metrics",
7454+
"layout.box.header.Patent.altmetrics": "Metrics",
7455+
"layout.box.header.Patent.usagemetrics": "Metrics",
7456+
"layout.box.header.Product.details": "Details",
7457+
"layout.box.header.Product.metrics": "Metrics",
7458+
"layout.box.header.Product.altmetrics": "Metrics",
7459+
"layout.box.header.Product.usagemetrics": "Metrics",
7460+
7461+
// Layout - Autogenerated i18n keys: metadata
7462+
7463+
"layout.field.label.OrgUnit.[organization.address.addressCountry]": "Country",
7464+
"layout.field.label.OrgUnit.[organization.address.addressLocality]": "City",
7465+
"layout.field.label.OrgUnit.[dc.description.abstract]": "Description",
7466+
"layout.field.label.OrgUnit.[crisou.boards]": "Boards",
7467+
"layout.field.label.OrgUnit.[dc.title]": "Organisation Name",
7468+
"layout.field.label.Project.[dc.description.abstract]": "Description",
7469+
"layout.field.label.Project.[dc.subject]": "Keywords",
7470+
"layout.field.label.Project.[oairecerif.acronym]": "Acronym",
7471+
"layout.field.label.Project.[crispj.coordinator]": "Consortium Coordinator",
7472+
"layout.field.label.Project.[crispj.partnerou]": "Partner Organisations",
7473+
"layout.field.label.Project.[crispj.investigator]": "Principal Investigator",
7474+
"layout.field.label.Project.[crispj.coinvestigators]": "Investigators",
7475+
"layout.field.label.Project.[crispj.organization]": "Organisations",
7476+
"layout.field.label.Project.[dc.relation.equipment]": "Uses",
7477+
"layout.field.label.Project.[oairecerif.identifier.url]": "Project Web Site",
7478+
"layout.field.label.Project.[crispj.openaireid]": "OpenAIRE ID",
7479+
"layout.field.label.Funding.[dc.relation.project]": "Project",
7480+
"layout.field.label.Funding.[dc.type]": "Type",
7481+
"layout.field.label.Funding.[oairecerif.funder]": "Funder",
7482+
"layout.field.label.Funding.[oairecerif.fundingParent]": "Funding Program",
7483+
"layout.field.label.Funding.[oairecerif.identifier.url]": "Award URL",
7484+
"layout.field.label.Funding.[oairecerif.oamandate]": "OA Mandate",
7485+
"layout.field.label.Funding.[oairecerif.internalid]": "Funding code",
7486+
"layout.field.label.Funding.[oairecerif.amount]": "Amount",
7487+
"layout.field.label.Funding.[oairecerif.amount.currency]": "Currency",
7488+
"layout.field.label.Person.[dc.subject]": "Research Interests",
7489+
"layout.field.label.Person.[person.knowsLanguage]": "Knows Language",
7490+
"layout.field.label.Person.[dc.title]": "Preferred name",
7491+
"layout.field.label.Person.[crisrp.name]": "Official Name",
7492+
"layout.field.label.Person.[crisrp.name.translated]": "Translated Name",
7493+
"layout.field.label.Person.[crisrp.name.variant]": "Alternative Name",
7494+
"layout.field.label.Person.[person.affiliation.name]": "Main Affiliation",
7495+
"layout.field.label.Person.[oairecerif.identifier.url]": "Web Site",
7496+
"layout.field.label.Person.[person.email]": "Email",
7497+
"layout.field.label.Person.[person.identifier.orcid]": "ORCID",
7498+
"layout.field.label.Person.[person.identifier.scopus-author-id]": "Scopus Author ID",
7499+
"layout.field.label.Person.[person.identifier.rid]": "Researcher ID",
7500+
"layout.field.label.Person.[dc.description.abstract]": "Biography",
7501+
"layout.field.label.Person.[oairecerif.person.affiliation]": "Affiliation",
7502+
"layout.field.label.Person.[crisrp.education]": "Education",
7503+
"layout.field.label.Person.[crisrp.country]": "Country",
7504+
"layout.field.label.Person.[person.birthDate]": "Birth Date",
7505+
"layout.field.label.Journal.[dc.title]": "Journal Title",
7506+
"layout.field.label.Journal.[dc.subject]": "Keywords",
7507+
"layout.field.label.Journal.[dc.identifier.issn]": "ISSN",
7508+
"layout.field.label.Event.[dc.title]": "Title",
7509+
"layout.field.label.Event.[oairecerif.event.startDate]": "Start Date",
7510+
"layout.field.label.Event.[oairecerif.event.endDate]": "End Date",
7511+
"layout.field.label.Event.[oairecerif.event.place]": "Location",
7512+
"layout.field.label.Event.[dc.type]": "Type",
7513+
"layout.field.label.Event.[crisevent.organizerou]": "Organizer",
7514+
"layout.field.label.Event.[crisevent.organizerpj]": "Organizer",
7515+
"layout.field.label.Event.[crisevent.sponsorou]": "Sponsor",
7516+
"layout.field.label.Event.[crisevent.sponsorpj]": "Sponsor",
7517+
"layout.field.label.Event.[crisevent.partnerou]": "Partner Organisation",
7518+
"layout.field.label.Event.[crisevent.partnerpj]": "Partner Project",
7519+
"layout.field.label.Event.[oairecerif.acronym]": "Acronym",
7520+
"layout.field.label.Event.[dc.description.abstract]": "Abstract",
7521+
"layout.field.label.Event.[dc.subject]": "Keywords",
7522+
"layout.field.label.Event.[oairecerif.event.country]": "Country",
7523+
"layout.field.label.Equipment.[oairecerif.acronym]": "Acronym",
7524+
"layout.field.label.Equipment.[dc.description]": "Description",
7525+
"layout.field.label.Equipment.[oairecerif.internalid]": "Internal ID",
7526+
"layout.field.label.Equipment.[dc.title]": "Name",
7527+
"layout.field.label.Equipment.[crisequipment.ownerou]": "Owner Organisation",
7528+
"layout.field.label.Publication.[dc.relation.ispartof]": "Journal",
7529+
"layout.field.label.Publication.[dc.relation.issn]": "ISSN",
7530+
"layout.field.label.Publication.[dc.date.issued]": "Date Issued",
7531+
"layout.field.label.Publication.[dc.contributor.author]": "Author 228",
7532+
"layout.field.label.Publication.[dc.contributor.editor]": "Editor(s)",
7533+
"layout.field.label.Publication.[dc.identifier.doi]": "DOI",
7534+
"layout.field.label.Publication.[dc.description.abstract]": "Abstract",
7535+
"layout.field.label.Publication.[dc.relation.project]": "Project(s)",
7536+
"layout.field.label.Publication.[dc.relation.funding]": "Funding(s)",
7537+
"layout.field.label.Publication.[dc.subject]": "Subjects",
7538+
"layout.field.label.Publication.[BITSTREAM]": "File(s)",
7539+
"layout.field.label.Product.[dc.title]": "Title",
7540+
"layout.field.label.Product.[dc.relation.ispartof]": "Journal",
7541+
"layout.field.label.Product.[dc.relation.issn]": "ISSN",
7542+
"layout.field.label.Product.[dc.date.issued]": "Date Issued",
7543+
"layout.field.label.Product.[dc.contributor.author]": "Author(s)",
7544+
"layout.field.label.Product.[dc.identifier.doi]": "DOI",
7545+
"layout.field.label.Product.[dc.description.abstract]": "Abstract",
7546+
"layout.field.label.Product.[dc.relation.project]": "Project(s)",
7547+
"layout.field.label.Product.[dc.relation.funding]": "Funding(s)",
7548+
"layout.field.label.Product.[dc.subject]": "Subjects",
7549+
"layout.field.label.Product.[BITSTREAM]": "File(s)",
7550+
"layout.field.label.Patent.[dc.title]": "Title",
7551+
"layout.field.label.Patent.[dc.relation.ispartof]": "Journal",
7552+
"layout.field.label.Patent.[dc.relation.issn]": "ISSN",
7553+
"layout.field.label.Patent.[dc.date.issued]": "Date Issued",
7554+
"layout.field.label.Patent.[dc.contributor.author]": "Author(s)",
7555+
"layout.field.label.Patent.[dc.identifier.patentno]": "DOI",
7556+
"layout.field.label.Patent.[dc.description.abstract]": "Abstract",
7557+
"layout.field.label.Patent.[dc.relation.project]": "Project(s)",
7558+
"layout.field.label.Patent.[dc.relation.funding]": "Funding(s)",
7559+
"layout.field.label.Patent.[dc.subject]": "Subjects",
7560+
"layout.field.label.Patent.[BITSTREAM]": "File(s)",
7561+
7562+
7563+
// Layout - Autogenerated i18n keys: metadata groups
7564+
7565+
"layout.field.label.Person.[crisrp.qualification].[crisrp.qualification]": "Title",
7566+
"layout.field.label.Person.[crisrp.qualification].[crisrp.qualification.start]": "Start",
7567+
"layout.field.label.Person.[crisrp.qualification].[crisrp.qualification.end]": "End",
7568+
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.affiliation.role]": "Role",
7569+
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.person.affiliation]": "Organisation",
7570+
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.affiliation.startDate]": "Start",
7571+
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.affiliation.endDate]": "End",
7572+
"layout.field.label.Person.[crisrp.education].[crisrp.education.role]": "Role",
7573+
"layout.field.label.Person.[crisrp.education].[crisrp.education]": "Organisation",
7574+
"layout.field.label.Person.[crisrp.education].[crisrp.education.start]": "Start",
7575+
"layout.field.label.Person.[crisrp.education].[crisrp.education.end]": "End",
7576+
"layout.field.label.Publication.[dc.contributor.author].[dc.contributor.author]": "Author",
7577+
"layout.field.label.Publication.[dc.contributor.author].[oairecerif.author.affiliation]": "Affiliation",
7578+
"layout.field.label.Publication.[dc.contributor.editor].[dc.contributor.editor]": "Editor",
7579+
"layout.field.label.Publication.[dc.contributor.editor].[oairecerif.editor.affiliation]": "Affiliation",
7580+
"layout.field.label.Product.[dc.contributor.author].[dc.contributor.author]": "Creator",
7581+
"layout.field.label.Product.[dc.contributor.author].[oairecerif.author.affiliation]": "Affiliation",
7582+
"layout.field.label.Patent.[dc.contributor.author].[dc.contributor.author]": "Inventor",
7583+
"layout.field.label.Patent.[dc.contributor.author].[oairecerif.author.affiliation]": "Affiliation",
7584+
7585+
7586+
// Do not add new labels below layout ones
7587+
// All new labels should be placed together with similar ones, or in alphabetical orders
73817588
}

0 commit comments

Comments
 (0)