Fix #4241 language selection by AbhinavS96 · Pull Request #4805 · DSpace/dspace-angular · GitHub
Skip to content

Fix #4241 language selection#4805

Merged
tdonohue merged 4 commits into
DSpace:mainfrom
atmire:fix-4241-language-selection-contribute-main
Nov 17, 2025
Merged

Fix #4241 language selection#4805
tdonohue merged 4 commits into
DSpace:mainfrom
atmire:fix-4241-language-selection-contribute-main

Conversation

@AbhinavS96

@AbhinavS96 AbhinavS96 commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

References

Description

This fixes an issue where the language set in the user's profile was not being applied. It also addresses a problem where the default browser language was sometimes ignored. Portuguese (Portugal) (pt-PT) and Portuguese (Brazil) (pt-BR) will now be correctly used when defined in the browser's language settings. I also fixed the issue where only the first browser language was ever considered.

NOTE: The behavior of the language cookie was changed. It will now only be saved if the user manually selects a language using the language switch. Otherwise, the language will be inferred from the browser settings or the EPerson’s profile.

Instructions for Reviewers

List of changes in this PR:

  • Locale service checks for the preferred language of a logged in user before setting a fallback
  • Tries to fallback to browser default
  • Sets a language in the cookie only if the user manually changes the language. Afterwards, this will remain the default.

To test:

  1. Change the language of your browser to something in the DSpace language dropdown (not english)
  2. Delete the dsLanguage cookie if it exists
  3. On page load, the language should now be the browser default
  4. Login and set the language in the user profile to a third language.
  5. Refresh and the language should be the one set in the profile
  6. Log out and the language should be back to the browser default.
  7. Select a language from the language picker.
  8. From this point, no action (login/logout) should change the language further. Additionally verify that this is set in the dsLanguage cookie.

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.

abhinav added 2 commits November 6, 2025 16:46
Consider the language set in the users profile when setting it on page load. Also match languages case-insensitive. Updated tests
@alexandrevryghem alexandrevryghem added bug i18n / l10n Internationalisation and localisation, related to message catalogs authentication: general general authentication issues authentication: password related to built in password authentication port to dspace-7_x port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release port to dspace-9_x This PR needs to be ported to `dspace-9_x` branch for next bug-fix release labels Nov 6, 2025
@alexandrevryghem alexandrevryghem moved this to 🙋 Needs Reviewers Assigned in DSpace 10.0 Release Nov 6, 2025
@alexandrevryghem alexandrevryghem added this to the 10.0 milestone Nov 6, 2025
@github-actions

Copy link
Copy Markdown

@AbhinavS96 AbhinavS96 force-pushed the fix-4241-language-selection-contribute-main branch from dbcf5d4 to 58b7b03 Compare November 13, 2025 17:16
@github-actions

Copy link
Copy Markdown

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

@AbhinavS96 AbhinavS96 marked this pull request as ready for review November 14, 2025 08:41

@nwoodward nwoodward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 Thanks @AbhinavS96! I tested this PR with all the given scenarios, and the language selection updated each time.

@github-project-automation github-project-automation Bot moved this from 🙋 Needs Reviewers Assigned to 👍 Reviewer Approved in DSpace 10.0 Release Nov 14, 2025

@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.

@AbhinavS96 : Maybe I'm misunderstanding the point of this PR, but I'm not able to change the language in my user profile and have it take affect in DSpace, even after logout.

Here's what I tried to do:

  1. Login as a user. Visit the user's "Profile" page (/profile)
  2. On that page, select a non-English language. I chose "Deutsch" (German)
  3. Click "Save" button on the Profile page.
  4. Logout
  5. Login again as that user. Verify the Profile still says "Deutsch". However, DSpace is not displaying German. Instead, it's still showing default English text.

Am I misunderstanding how this is supposed to act if a user changes their Language in their Profile?

@alexandrevryghem

Copy link
Copy Markdown
Member

@tdonohue: Did you try clearing your cookies? Currently on main, DSpace always auto-populates the value in the language cookie with the best match it can find, so your dsLanguage cookie probably still has English saved as your preferred language. With this PR, the dsLanguage cookie will now only be set when you select a language from the language switch.

This means that the new order of importance for selecting the language is:
dsLanguage cookie (= manual selection in language switch) > preferred EPerson language > preferred browser languages

By prioritizing the dsLanguage cookie over the EPerson’s preference, users who aren’t aware of the profile language setting won’t have their chosen language in the header’s language switch continually reset with the one from their preferences.

@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 @AbhinavS96 ! And thank you for clarifying the expected behavior @alexandrevryghem ! I had previous misunderstood the order of precedence. But, I can now verify that the globe button (in header) has the highest precedence (via the dsLanguage cookie). But, if that cookie is unset, I can verify the language in the user profile has the next highest precedence. (So, my test above works if you unset the dsLanguage cookie.)

Code looks good too!

@tdonohue tdonohue merged commit bf04527 into DSpace:main Nov 17, 2025
15 checks passed
@github-project-automation github-project-automation Bot moved this from 👍 Reviewer Approved to ✅ Done in DSpace 10.0 Release Nov 17, 2025
@dspace-bot

Copy link
Copy Markdown
Contributor

Backport failed for dspace-7_x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin dspace-7_x
git worktree add -d .worktree/backport-4805-to-dspace-7_x origin/dspace-7_x
cd .worktree/backport-4805-to-dspace-7_x
git switch --create backport-4805-to-dspace-7_x
git cherry-pick -x 7da01d80d810d0da5668ef045001b9a73711b300 58b7b03d19bbc02d4d42c24a2062538a410582d9

@dspace-bot

Copy link
Copy Markdown
Contributor

Backport failed for dspace-8_x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin dspace-8_x
git worktree add -d .worktree/backport-4805-to-dspace-8_x origin/dspace-8_x
cd .worktree/backport-4805-to-dspace-8_x
git switch --create backport-4805-to-dspace-8_x
git cherry-pick -x 7da01d80d810d0da5668ef045001b9a73711b300 58b7b03d19bbc02d4d42c24a2062538a410582d9

@dspace-bot

Copy link
Copy Markdown
Contributor

Backport failed for dspace-9_x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin dspace-9_x
git worktree add -d .worktree/backport-4805-to-dspace-9_x origin/dspace-9_x
cd .worktree/backport-4805-to-dspace-9_x
git switch --create backport-4805-to-dspace-9_x
git cherry-pick -x 7da01d80d810d0da5668ef045001b9a73711b300 58b7b03d19bbc02d4d42c24a2062538a410582d9

@tdonohue

Copy link
Copy Markdown
Member

@alexandrevryghem alexandrevryghem deleted the fix-4241-language-selection-contribute-main branch November 18, 2025 13:36
@alexandrevryghem alexandrevryghem removed port to dspace-7_x port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release port to dspace-9_x This PR needs to be ported to `dspace-9_x` branch for next bug-fix release labels Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

authentication: general general authentication issues authentication: password related to built in password authentication bug i18n / l10n Internationalisation and localisation, related to message catalogs

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

The language set in the user's profile does not have any effect on the selected language

5 participants