Bug with media library and LanguageNegotiationUserAdmin

Created on 1 December 2023, 7 months ago
Updated 23 January 2024, 5 months ago

Problem/Motivation

I believe I have uncovered a bug with LanguageNegotiationUserAdmin and the Media Library core module

In my use case, I have a multi lingual site but the users want to select their personal admin interface language (in my case, all admin pages should be in English)

However, when adding a new file uploaded through the media library i'm seeing translations on the second step. (Add media item, select file upload)

From what I can gather, this seems to be an issue during language negotiation, specifically LanguageNegotiationUserAdmin and:

    // User preference (only for administrators).
    if (($this->currentUser->hasPermission('access administration pages') || $this->currentUser->hasPermission('view the administration theme')) && ($preferred_admin_langcode = $this->currentUser->getPreferredAdminLangcode(FALSE)) && $this->isAdminPath($request)) {
      $langcode = $preferred_admin_langcode;
    }

This conditional always fails, because $this->isAdminPath($request) is false for the media library route. The route in question is path: '/media-library' from media_library.ui and media_library.routing.yml

Steps to reproduce

1. Fresh install of D10
2. Enable media library and language
3. Have 2 site languages, English as the default, and say Chinese for the second
4. Configure Interface text language detection as 'Account administration pages', first and 'URL' second
5. Edit user 1's language preference to be English for admin pages
6. Enable content translations
7. Add a content type, or alter one of the core ones
8. Add a media entity reference field to "image"
9. Add a new node, of type from step 5
10. Add an image to the image field
11. Save
12. Translate this node, select Chinese
13. Add a new media item in the image field from step 8
14. Select to upload a new file in the widget
15. Make a note of some of the strings in this modal, for example "Remove"
16. Add a user interface translation, for "Remove" in Chinese
17. Go back to translate again
18. Add a media item, select file upload

Expected - the users admin language choice should be respected, the translation added for step 16 should not show. All strings should be in English

Actual - the translation added for Chinese is displayed despite the users preferred language in their profile

Proposed resolution

For my particular use case this route should always be an admin path, so I can assign it as such and translations work as expected but not sure whether this could have wider implications for sites that allow anonymous users access to the media library.

πŸ› Bug report
Status

Active

Version

10.2 ✨

Component
MediaΒ  β†’

Last updated about 10 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom aaron.ferris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024