Skip to content

Add lang attribute to elements showing metadata values#4776

Merged
tdonohue merged 12 commits into
DSpace:mainfrom
4Science:task/main/CST-19328
May 20, 2026
Merged

Add lang attribute to elements showing metadata values#4776
tdonohue merged 12 commits into
DSpace:mainfrom
4Science:task/main/CST-19328

Conversation

@AndreaBarbasso

Copy link
Copy Markdown
Contributor

References

Description

Applied lang attribute to HTML tags containing metadata with an explicit language value.

Instructions for Reviewers

The lang attribute has been added via different approaches:

  • If the metadata string value was shown via innerHTML, that property has now been replaced with the new dsMetadata directive, that accepts a MetadataValue and applies the innerHTML property and the lang attribute to its host element. Having a directive for this purpose is useful since we can later add other attributes if necessary and is more feasible than a component.
  • Otherwise, the lang attribute has been applied to the closest available element.

List of changes in this PR:

  • Created and applied the new dsMetadata directive;
  • Applied the lang attribute where using the directive could lead to unwanted behaviors.
image

To test the PR, change any metadata language value and make sure that the value is added to the lang attribute of its containing element, wherever it's reflected (e.g. item pages, search results, ...).

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@AndreaBarbasso AndreaBarbasso changed the title Task/main/cst 19328 Add lang attribute to elements showing metadata values Oct 16, 2025
@AndreaBarbasso

AndreaBarbasso commented Oct 16, 2025

Copy link
Copy Markdown
Contributor Author

@tdonohue, tests are failing because of invalid values for the lang attribute.

A lot of metadata fields have the language set to en_US, but the correct value is en-US.
I think the best course of action here is avoiding front-end manipulation of those values, and change them on the fixture instead.

EDIT: after further research, I see that the difference is caused by different standards for in web technologies (IETF BCP 47) and Java/POSIX systems.
So, I guess the best course of action is to convert them on the front-end.

@AndreaBarbasso

Copy link
Copy Markdown
Contributor Author

As discussed today, I am going to open an issue on the REST side to discuss if we need to change the chosen standard for language codes.
Meanwhile, I will add a simple way to make a11y tests pass and to give a valid string to lang attributes, by replacing the _ with a -.

@github-actions

Copy link
Copy Markdown

Hi @AndreaBarbasso,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

# Conflicts:
#	src/app/entity-groups/journal-entities/item-list-elements/search-result-list-elements/journal-issue/journal-issue-search-result-list-element.component.ts
#	src/app/entity-groups/journal-entities/item-list-elements/search-result-list-elements/journal-volume/journal-volume-search-result-list-element.component.ts
#	src/app/entity-groups/journal-entities/item-list-elements/search-result-list-elements/journal/journal-search-result-list-element.component.ts
#	src/app/entity-groups/research-entities/item-list-elements/search-result-list-elements/org-unit/org-unit-search-result-list-element.component.ts
#	src/app/entity-groups/research-entities/item-list-elements/search-result-list-elements/person/person-search-result-list-element.component.ts
#	src/app/entity-groups/research-entities/submission/item-list-elements/org-unit/org-unit-search-result-list-submission-element.component.ts
#	src/app/entity-groups/research-entities/submission/item-list-elements/person/person-search-result-list-submission-element.component.ts
#	src/app/shared/object-detail/my-dspace-result-detail-element/item-detail-preview/item-detail-preview-field/item-detail-preview-field.component.ts
#	src/app/shared/object-detail/my-dspace-result-detail-element/search-result-detail-element.component.ts
#	src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts
#	src/app/shared/object-list/metadata-representation-list-element/browse-link/browse-link-metadata-list-element.component.ts
#	src/app/shared/object-list/metadata-representation-list-element/plain-text/plain-text-metadata-list-element.component.ts
#	src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts
#	src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts
#	src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts
#	src/themes/custom/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.ts
@tdonohue tdonohue added accessibility component: Item (Archived) Item display or editing labels Nov 13, 2025
@tdonohue tdonohue moved this to 🙋 Needs Reviewers Assigned in DSpace 10.0 Release Nov 13, 2025
@github-actions

Copy link
Copy Markdown

Hi @AndreaBarbasso,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@jrcwiok jrcwiok left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Item page - language attribute shows up
Screenshot 2025-12-19 at 10 23 52
search results - language attribute does not show up - should it?
Screenshot 2025-12-19 at 10 35 35

Andrea Barbasso added 2 commits February 10, 2026 10:12
# Conflicts:
#	src/app/entity-groups/research-entities/metadata-representations/org-unit/org-unit-item-metadata-list-element.component.html
#	src/app/entity-groups/research-entities/metadata-representations/org-unit/org-unit-item-metadata-list-element.component.ts
#	src/app/entity-groups/research-entities/metadata-representations/person/person-item-metadata-list-element.component.html
#	src/app/entity-groups/research-entities/metadata-representations/person/person-item-metadata-list-element.component.ts
#	src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.html
#	src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.html
@alegontarz

Copy link
Copy Markdown

QA testing performed (no code review).
Working as expected:

  1. Metadata values with an explicit language (e.g. publisher, abstract) correctly receive the lang attribute.
    Not working as expected:
  2. Observed that the Title (dc.title) does not have a lang attribute applied, even when a language value is set.

@alegontarz alegontarz moved this from 🙋 Needs Reviewers Assigned to 🏗 In Progress in DSpace 10.0 Release Feb 20, 2026
@tdonohue tdonohue moved this from 🏗 In Progress to 👍 Reviewer Approved in DSpace 10.0 Release Feb 20, 2026
@github-actions

Copy link
Copy Markdown

Hi @AndreaBarbasso,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@tdonohue

Copy link
Copy Markdown
Member

@AndreaBarbasso : Could you update this PR to solve the merge conflict when you have a chance? Thanks!

…T-19328

# Conflicts:
#	src/app/item-page/field-components/metadata-values/metadata-values.component.html
#	src/app/item-page/field-components/metadata-values/metadata-values.component.spec.ts
#	src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.html
#	src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.ts
#	src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.html
#	src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.ts
#	src/themes/custom/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.ts
#	src/themes/custom/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.ts

@tdonohue tdonohue left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreaBarbasso : Thanks for this PR. I've tested & reviewed it today. Overall, the basics are working...but I can reproduce the issues reported by others above:

  1. In the search results, the lang attribute never exists if hit highlighting has occurred. To reproduce:
    • Find an Item, add an abstract and set the language.
    • Verify the lang attribute exists in the Abstract on the Item page
    • Now search for a term in the abstract.
    • Verify the lang attribute does NOT exist in the Abstract in the search results when hit highlighting occurs. Is it supposed to have a lang attribute?
    • (However, I can verify the lang attribute does exist if you just browse to the item and don't trigger hit highlighting)
  2. The title of an Item never shows a lang attribute. To reproduce:
    • Find an Item and set the language of the Title (dc.title) to "en" (or any other value).
    • Verify on the Item page that the Title field doesn't have a lang attribute`.
    • This seems like a bug as the Title should display a language when one exists.

I have a few other inline comments below. There's a few methods that are repeated in several areas of the code and I think it'd be better to not repeat them. I'm also trying to understand why you needed to create these methods, so I feel they need a better description.

Beyond those issues, the basic functionality is working well.

* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
* @returns {MetadataValue[]} the matching values or an empty array.
*/
allMetadata(keyOrKeys: string | string[]): MetadataValue[] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this change is necessary in order to add the lang attribute? Why are we having to change our approach to getting all the metadata to include also the hitHighlights? I'm just not understanding the purpose behind this change, so that implies we may need to describe this method better as to why we need to do this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdonohue, to create this method I simply took the previously used method and changed it so that it returns an array of Metadata objects instead of an array of strings. I did this to avoid any regression issue and keep backwards compatibility.
I agree with it being found in too many places - that's an ongoing issue with some other methods in these files, but I can start by applying some DRY on this method!

* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
* @returns {MetadataValue[]} the matching values or an empty array.
*/
allMetadata(keyOrKeys: string | string[]): MetadataValue[] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticing this same method is repeated in several components. Is there a way we could pull this out into a utility method instead of repeating it over and over again?

* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
* @returns {MetadataValue} the first matching value, or `undefined`.
*/
firstMetadata(keyOrKeys: string | string[]): MetadataValue {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. This is repeated in several components. It'd be better not to repeat the same methods over and over...because if we find a bug in one we may not remember to fix all of them.

@github-project-automation github-project-automation Bot moved this from 👍 Reviewer Approved to 👀 Under Review in DSpace 10.0 Release Apr 13, 2026
@github-actions

Copy link
Copy Markdown

Hi @AndreaBarbasso,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

…19328

# Conflicts:
#	src/app/item-page/field-components/metadata-values/metadata-values.component.html
@AndreaBarbasso

Copy link
Copy Markdown
Contributor Author

@tdonohue, I applied the same logic to dso titles and hitHighlight-ed descriptions. I also refactored the code to improve DRYness.

@atarix83
atarix83 requested a review from tdonohue May 14, 2026 12:55

@tdonohue tdonohue left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreaBarbasso : I retested this today. While the hit highlighting bug is fixed, I'm still not seeing the lang=[lang-code] attribute on Item titles on the Item page. Here's how to reproduce it:

  1. Administer an Item and set the language of the Title (dc.title) to "en" (or any other value).
  2. Go back to the Item's page and view the source of the page.
  3. Notice that the Title field (displayed in an <h1>) does NOT have a lang attribute.
  4. However, if you search for that Item by it's title, the lang attribute WILL APPEAR if you view the source of the search results page.

@AndreaBarbasso

Copy link
Copy Markdown
Contributor Author

@tdonohue, my bad, I was so focused on the item title in search result elements that I forgot that part.
I'm pushing a new commit in a minute!

@AndreaBarbasso
AndreaBarbasso requested a review from tdonohue May 20, 2026 08:00
@tdonohue tdonohue added this to the 10.0 milestone May 20, 2026

@tdonohue tdonohue left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @AndreaBarbasso ! I've verified this is now working properly. Looks good to me now.

@github-project-automation github-project-automation Bot moved this from 👀 Under Review to 👍 Reviewer Approved in DSpace 10.0 Release May 20, 2026
@tdonohue
tdonohue merged commit bd203c9 into DSpace:main May 20, 2026
18 of 19 checks passed
@github-project-automation github-project-automation Bot moved this from 👍 Reviewer Approved to ✅ Done in DSpace 10.0 Release May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility component: Item (Archived) Item display or editing

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

[Accessibility] lang attribute needed for metadata values

4 participants