Problem/Motivation

If the site has an admin language preference option set in negotiation, users can set their admin language preference. However, even if that is set, only admin pages are affected. The admin toolbar is not. The admin toolbar displayed on non-admin pages will use the language of that page, not the admin language.

Proposed resolution

Negotiate an admin language for the toolbar and use that to render the menu.

Remaining tasks

Update release notes snippet and change record.

User interface changes

The admin toolbar will be in an admin-appropriate language.

API changes

See release notes snippet.

Release notes snippet

- \Drupal\user\ToolbarLinkBuilder requires now a new parameter of type \Drupal\Core\Extension\ModuleHandlerInterface. Custom modules extending ToolbarLinkBuilder should adjust the code accordingly.
- New cache context: \Drupal\Core\Cache\Context\AccountAdminLanguageCacheContext
- New method setCurrentLanguage introduced to LanguageManager
- New service: \Drupal\language\AdminLanguageRender

CommentFileSizeAuthor
#257 2313309-244-admin-toolbar-and-contextual-links-admin-language--D11.3-no-umami-tests--20260506-2.patch49.05 KBrecrit
#245 2313309-nr-bot_9lz9dxqp.txt90 bytesneeds-review-queue-bot
#244 2313309-244-admin-toolbar-and-contextual-links-admin-language.patch54.68 KBdench0
#236 2313309-236.patch37.95 KBhmdnawaz
#234 2313309-nr-bot_6s1gtzxt.txt90 bytesneeds-review-queue-bot
#230 contextual-links-randomly-translated.mp4548.17 KBrobin.houtevelts
#222 2313309-nr-bot.txt90 bytesneeds-review-queue-bot
#221 Contribution-Guide-drupalpod-Gitpod-Code-11-06-2024_11_45_PM.png18.81 KBsagarmohite0031
#216 2313309-nr-bot.txt6.32 KBneeds-review-queue-bot
#206 Screenshot 2024-07-16 at 15.22.47.png111.88 KBronttizz
#206 Screenshot 2024-07-16 at 15.20.55.png11.7 KBronttizz
#206 Screenshot 2024-07-16 at 15.18.51.png20.48 KBronttizz
#179 2313309-179.patch32.53 KBlinhnm
#178 2313309-178.patch22.88 KBlinhnm
#175 2313309-MR4604-7975cb1f--20230912.diff33.06 KBrecrit
#173 2313309-173.patch43.88 KBtimohuisman
#172 2313309-172.patch.txt43.88 KBtimohuisman
#164 2313309-162-with-enable-option--164.patch32.64 KBleo liao
#162 2313309-162.patch32.51 KBjoao.ramos.costa
#161 reroll_diff_152-161.txt4.36 KBjoao.ramos.costa
#161 2313309-161.patch32.48 KBjoao.ramos.costa
#160 2313309-160.patch32.48 KBn.ghunaim
#159 2313309-159.patch34.27 KBmichaelsoetaert
#158 2313309-143-with-enable-option--158.patch34.19 KBleo liao
#153 navbar.png18.15 KBahmad abbad
#152 2313309-152.patch32.47 KBborisson_
#148 2313309-127-with-enable-option--3101231-19.patch22.09 KBguaneagler
#146 2313309-127--3101231-19-combine.patch20.37 KBguaneagler
#143 interdiff_141-143.txt2.47 KBakashkumar07
#143 2313309-143.patch32.47 KBakashkumar07
#141 2313309-136-added-misssing-line-in-dictionary-txt.patch32.29 KBovanes
#135 interdiff-2313309-133-135.txt3.46 KBjeroent
#135 2313309-135.patch32.31 KBjeroent
#133 2313309-2-133.patch28.71 KBalexpott
#133 131-133-interdiff.txt30.14 KBalexpott
#131 2313309-130.patch29.08 KBcgoffin
#127 2313309-127.patch27.43 KBtimohuisman
#122 interdiff_116-122.txt8.68 KBunstatu
#122 2313309-122.patch25.8 KBunstatu
#118 2313309-117.patch25.53 KBemek
#116 interdiff_115-116.txt218 bytesvsujeetkumar
#116 2313309-116.patch25.5 KBvsujeetkumar
#115 2313309-115.patch25.2 KBemek
#114 2313309-114.patch25.04 KBseyfettinkahveci
#100 2313309-100-test-only.patch16.71 KBduaelfr
#100 2313309-100.patch25.57 KBduaelfr
#92 interdiff-2313309-87-91.txt16.3 KBjeroent
#91 2313309-91-test-only.patch16.79 KBjeroent
#91 2313309-91.patch25.35 KBjeroent
#90 2313309-90-test-only.patch16.48 KBjeroent
#90 2313309-90.patch25.04 KBjeroent
#89 2313309-89.patch25.04 KBjeroent
#89 2313309-89-test-only.patch16.48 KBjeroent
#87 interdiff-2313309-85-87.txt661 bytesjeroent
#87 2313309-87.patch9.01 KBjeroent
#85 interdiff-2313309-83-85.txt1.05 KBjeroent
#85 2313309-85.patch9 KBjeroent
#83 interdiff-2313309-82-83.txt437 bytesjeroent
#83 2313309-83.patch8.98 KBjeroent
#82 interdiff-2313309-81-82.txt19.33 KBjeroent
#82 2313309-82.patch8.98 KBjeroent
#81 2313309-81.patch31.44 KBnwom
#78 interdiff_76-78.txt17.39 KBnikitagupta
#78 2313309-78.patch31.17 KBnikitagupta
#76 interdiff_74_76.txt1.48 KBanmolgoyal74
#76 2313309-76.patch6.42 KBanmolgoyal74
#74 interdiff_68_74.txt2.94 KBanmolgoyal74
#74 2313309-74.patch6.41 KBanmolgoyal74
#68 2313309-68.patch6.39 KBjeroent
#67 2313309-67.patch5.51 KBaimevp
#64 interdiff-44-64.txt818 byteshardik_patel_12
#64 2313309-64.patch5.53 KBhardik_patel_12
#58 Screenshot 2019-07-18 at 14.29.52.png17.52 KBdionsj
#44 2313309-44.patch5.55 KBguncha25
#43 2313309-43.patch4.27 KBandreyjan
#43 interdiff_40-43.txt3.09 KBandreyjan
#40 2313309-40.patch3.25 KBcasey
#29 2313309-toolbar-language-29.patch19.74 KBlba_emanuel
#7 2313309-toolbar-language-7.patch18.31 KBgábor hojtsy
#7 2313309-toolbar-language-test-only-and-interdiff.patch2.78 KBgábor hojtsy
#6 interdiff.txt605 bytesgábor hojtsy
#6 2313309-toolbar-language-6.patch15.53 KBgábor hojtsy
#2 2313309-toolbar-language.patch15.52 KBgábor hojtsy

Issue fork drupal-2313309

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

plach’s picture

+1 for an admin language type, it could be used for other UI elements such as local tasks/actions and contextual links.

gábor hojtsy’s picture

Status: Active » Needs work
StatusFileSize
new15.52 KB

This is way more trickier than I thought. Some problems:

  1. The "admin" toolbar is kind a myth. The toolbar is even capable of showing up for anonymous, and it is not dependent on admin permissions being there. So that we would need to render it in the admin language is not necessarily true.
  2. The admin menu part (tree under Manage) is rendered in a separate request and it gets a langcode at the END OF the URL, but that is not actually participating in the rendering of the menu, the rendering itself depends on the negotiation/path prefix. The langcode is merely passed on because the originating request caches generates a hash based on the language of the originating page and to recreate that, it is passed on. The language of the two pages may be different and the admin menu is generated in the toolbar request page's language regardless of the original language.
  3. Most initially visible parts of the toolbar are not admin focused and are generated within the original request. The shell for the upper and lower parts, the items for shortcuts, users, etc. These would need a language figured out and passed along in hook_toolbar() BUT again which of these are admin items? It is possible that when an admin language preference is used, even the user profile items would want to be forced to be in the admin language but otherwise no.

Here is a sketch of a patch for an admin language assuming if an admin is viewing the toolbar, they always want the toolbar in their admin preferred language. Otherwise it uses the page's language, but looks more elaborate just so we can pass around the langcode needed. Also modified the toolbar path to be an admin path, so the menu generated there will be in the admin language as well.

These are all theories, I could not really prove that this works yet :D I have some hard to debug issues here.

gábor hojtsy’s picture

@plach: yeah an admin language type would be a possible solution for this, but what language an admin page resolves to depends on specific config vs. the path used to access it, so not sure how a new type would work?

gábor hojtsy’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2313309-toolbar-language.patch, failed testing.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new15.53 KB
new605 bytes

Duh, fix invoke pattern.

gábor hojtsy’s picture

All right, here is a test that proves the problem. It will still fail once with the "fix" included because the fix is not complete. The top level items of the toolbar are rendered in the admin language but the menu is not. There is no way to ask for the menu to be rendered in a specific language that I know of, it just uses the language of the page :/ That would be the last potion to solve this.

Status: Needs review » Needs work

The last submitted patch, 7: 2313309-toolbar-language-7.patch, failed testing.

The last submitted patch, 7: 2313309-toolbar-language-test-only-and-interdiff.patch, failed testing.

gábor hojtsy’s picture

Yeah results exactly as expected. If we can figure out how to render the top menu items in the admin language, then it would resolved.

plach’s picture

I still think a new language type could be the solution here: if we define a non-configurable admin language type having as hardcoded negotiation settings something like admin language > UI language, then every UI element can decide whether it is and administrative item and default to the current Admin language. It shouldn't be hard to add a flag to a menu definition to mark it as "administrative".

gábor hojtsy’s picture

I would not hardcode that because if you have admin negotiation enabled, then admin users have the setting show up. If you don't want that, then you would not have a way to disable it. If we want this by default, then maybe we want an admin type that is configurable but is not configured by default (like content language).

plach’s picture

IIRC the user admin page checks whether the admin language detection methods is enabled for the UI language type, if not it should be very easy to add a check. Anyway, do you think it would really make sense to configure an Admin language type? IMHO its meaning is pretty well-defined, not sure what alternative choices the user would be supposed to make.

gábor hojtsy’s picture

Well, if we are to have an admin language type, then what it is useful for to have the admin negotiation enabled in the UI type? You would have it enabled in the admin type, right? :)

gábor hojtsy’s picture

Issue tags: +Drupalaton 2014
plach’s picture

Yes, but the current UI is pretty confusing if one has just to enable/disable admin language support. Wouldn't a single custom checkbox work better?

gábor hojtsy’s picture

That sounds pretty special that your admin language would work if the admin language TYPE is enabled to be customized, which would have the admin language negotiator enabled all the time?! Not sure tying that to the customization checking on the admin type is a good idea?!

plach’s picture

I am not sure I follow, I'll try to recap my proposal to see whether I can explain it better:

  • the admin language type is non-configurable and locked (like the URL one), so no table is ever exposed for it
  • the locked negotiation configuration is admin language > UI language
  • a checkbox somewhere in the "Detection and selection" page (probably on top) lets the user enable/disable admin language support (I'd make it opt-out, btw)
  • the admin language detection method checks the configuration value tied to the checkbox to decide whether returning a value or not, otherwise the fallback is the regular UI language
  • the admin language selector is displayed on user account pages only if the configuration value above is TRUE

Edit: The admin language detection method is bound to the admin language type and cannot be used elsewhere.

gábor hojtsy’s picture

Yeah that custom checkbox bothers me then... I thought we could make this work with the negotiation setting or the type setting or somesuch... I agree the combination of needing to enable the type and then the negotiation within is painful :/

plach’s picture

We could also leave it always enabled and use a NULL default for users, so that Admin language is not active until explicitly configured. We could also add a permission to control access to the widget on user pages.

gábor hojtsy’s picture

Yeah we already use a null default for users since #2313157: Optimize admin language detection and make it optional (admittedly one day ago :D).

gábor hojtsy’s picture

Issue tags: -sprint

Not being worked on.

The last submitted patch, 7: 2313309-toolbar-language-test-only-and-interdiff.patch, failed testing.

reekris’s picture

I am currently experiencing this issue in a Drupal 8 project using 8.0.5. I opened a related issue before finding this one #2688741: Administration pages language ignored in toolbar when viewing regular pages. It could probably be closed in favor of this one?

From reading through this thread it seems that #18 sound very similar to the Administration pages languagethat is currently in core, but it would be much more usable than the current solution. I don't see any good use case for wanting to have admin pages including the toolbar in a special language but not when viewing non-admin pages. In my opinion it would be much better with an "admin language" setting, that affected admin pages, admin toolbar, contextual items, drupal messages. etc everything that is seen as an admin string, no matter what page you are on.

Would it be possible to progress further on this issue and maybe get a fix in 8.0.x or is it postponed?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lba_emanuel’s picture

I will work on this patch re-roll for few hours.

lba_emanuel’s picture

StatusFileSize
new19.74 KB

As 2313309-toolbar-language-7.patch didn't apply anymore.
I had to rewrite all in every files 8.2.x . So didn't created an interdiff.
So my patch covers the same previous patch. I didn't had time to take into account comment since #7
Still need work.

olafski’s picture

We have #2313309: Admin toolbar should always be rendered in the admin language (if set) for that, which did not see to have much interest from users so far unfortunately :/

(Gábor Hojtsy, https://www.drupal.org/node/2189267#comment-11754752)

@Gábor Hojtsy - Unfortunately I can't help coding but I'm very interested in this issue which is quite important in my opinion.

@lba_emanuel - Are you planning to continue your work on the issue? Does it make sense to test the last patch, or should I wait?

Mojtaba Reyhani’s picture

I added a RTL Language translation File (Like: Persian, Farsi) to my drupal 8 site and What I simply want is to All "Administration Pages language" (or backend Language) in english only and all admin menu Always in left side and frontend pages of the site(Site Language) in another language (Like: persian, Farsi)
I do below setting:

1- I enabled the Language module, and set-up one additional language. Install was done in En (english), and I added Fa (Persian) language.
Language Module Configuration
Language Module Configuration

2- I configure the administration language separate to the content language by below setting:

/admin/config/regional/language/detection:
Account administration pages: enabled

Interface text language Configuration
Interface text language Configuration

3-Admin -> Edit Profile -> Edit(Tab)
Configuration of Administration Language
Configuration of Administration Language

This work properly for all administration page and those are English and in left side (LTR) except the "home page" and "user/1/" and admin/structure/block/demo/'Theme Name' of the site that the administration menu is in Persian Language and in right side (RTL) yet.

Administration Pages
Administration Pages

Home Page
Home Page

jimmyX’s picture

I followed Mojtaba Reyhani's steps, and I don't know if I have different expectations (he says this is working perfectly), but for me it does not work as expected. If I set the administration page language to English under Admin -> Edit Profile -> Edit(Tab), then I cannot edit any content in other languages; it only lets me edit pages in English. If I don't set that, then I can edit content in other languages, but then the admin toolbars are also shown in that other language. I can't tell if I'm doing something wrong, or if this is an ongoing issue.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mogio_hh’s picture

In Drupal 8.24 it is NOT working.

Admin language is set to "en" - still the tool bar is shown in "japanese" in my case. Can't read anything. So the existence of the toolbar is useless in frontend pages of foreign languages.

Anybody encounters the same issue?

svdhout’s picture

I've done a workaround for this problem by translating the local tasks and discovered links in a hook


define('BACKEND_LANGUAGE', 'en');

/**
 * Implements hook_menu_local_tasks_alter().
 * Translate all local tasks
 */
function language_frontend_local_tasks_alter(&$local_tasks) {
  foreach ($local_tasks as $key => $task) {
    if ($task['title'] InstanceOf \Drupal\Core\StringTranslation\TranslatableMarkup) {
      $options = $task['title']->getOptions();
      $options['langcode'] = BACKEND_LANGUAGE;
      $local_tasks[$key]['title'] = t($task['title']->getUntranslatedString(), $task['title']->getArguments(), $options);
    }
  }
}

/**
 * Implements hook_menu_links_discovered_alter().
 * Translate all local tasks that were not yet translated
 */
function language_frontend_menu_local_tasks_alter(&$data, $route_name) {
  foreach ($data['tabs'] as $key => $tab) {
    foreach ($tab as $route => $element) {
      $link = $element['#link'];
      if (!is_string($link['title']) && $link['title'] InstanceOf \Drupal\Core\StringTranslation\TranslatableMarkup) {
        $options = $link['title']->getOptions();
        $options['langcode'] = BACKEND_LANGUAGE;
        $data['tabs'][$key][$route]['#link']['title'] = t($link['title']->getUntranslatedString(), $link['title']->getArguments(), $options);
      }
    }
  }
}

I do not really like the workaround, but it seems to work for now.

jbfelix’s picture

Hello

How do you implement your workaround ?
In a module ?

nvaken’s picture

I think that workaround code is flawed, comments imply that this implements certain hooks while it actually doesn't apply to those hooks.

nvaken’s picture

What's the status of this issue? It seems that some assume that this already works as designed in D8? Though some of the others (include) seem to still get the admin menu in non-admin-language on the frontend of the site.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

casey’s picture

StatusFileSize
new3.25 KB

A (very hacky) fix to get this working for a client.

This also needs patches from:

What we really need, I think, is a generic way to switch languages during handling of a single request.

jbd44’s picture

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andreyjan’s picture

StatusFileSize
new3.09 KB
new4.27 KB

I have the following case:
Multi-site installation.
One of the sites is multilingual and the the other one is not. The site which is not multilingual is crashing with the error:
Call to undefined method Drupal\Core\Language\LanguageManager::setCurrentLanguage() in Drupal\toolbar\Element\Toolbar::switchToUserAdminLanguage()

Refactored #40 patch to check if the site is multilingual and also added some code improvements..
Not sure if it still can be committed to core, but it definitely needs to be covered by tests.

guncha25’s picture

StatusFileSize
new5.55 KB

Patch didn't really work with all menu. I have fixed user links and contextual links also.

matthiasm11’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

clairedesbois@gmail.com’s picture

Is that bug still relevant? I applied the patch from #2189267: When content language detection is different from interface language detection, the detected language is not applied to the rendered content. The admin toolbar works correctly and appears in english when I'm on the french version. My only problem now is the active tasks bar where menu items from administrative actions (Edit, Translate, etc.) appear in french instead of english.

I'm on Drupal 8.6.1.

nitebreed’s picture

Note that if you use the Admin Toolbar module (https://www.drupal.org/project/admin_toolbar), this patch doesn't have any effect!

upchuk’s picture

I also confirm #47.

RE #48, I believe that is outside the scope. Getting the core Toolbar working in the admin language is what needs to happen no?

johnwebdev’s picture

I think this should be done on a more generic level and not specifically towards Admin toolbar, as mentioned previously, i.e. if using something like Layout Builder I might want to display the interface in the administrative language.

upchuk’s picture

lpeabody’s picture

Status: Needs work » Reviewed & tested by the community

I'm operating on Drupal 8.6.7, and with this patch applied. I can confirm two things:

1) With this patch applied, admin_toolbar DOES render in the language specified in the user's administrative pages language settings.
2) Without this patch applied, admin_toolbar DOES NOT render against the user's administrative pages language setting.

The same is true about the toolbar on it's own (i.e. admin_toolbar uninstalled, toolbar enabled).

So, IMHO this patch is still needed. Given it works exactly as I expect it to, I'll switch this to RTBC.

plach’s picture

Version: 8.6.x-dev » 8.7.x-dev

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 44: 2313309-44.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sun-fire’s picture

All works fine for me with patch #44 (core version 8.6.12), but I had this issue without using of this patch. So, this patch is still needed.

tunic’s picture

I've created a similar issue but for local task labels (see #3054641: Local tasks should honor selected admin interface language (if set)).

If current issue doesn't address translation of Contextual Links I guess a new issue should be created. It seems this is addressed in #44, but is not mentioned in issue's title nor in the summary, we shouldn't forget it.

I've tested patch #44 and seems to work for the Admin Toolbar, but I've not clear results about contextual filters (I didn't work for one test, but given I've a heavily patched Drupal site probably was a secondary effect). Although tests still fail, ti works ok on a Drupal installation.

dionsj’s picture

StatusFileSize
new17.52 KB

@tunic I've been running the patch from #44 on several different sites we are working on and a local test site, and on all of them it seems that the contextual filters (quick edit etc.) have mixed translations for some reason, in the attached image it is of a site with 2 language (Installed with English, added Danish later and made it default language). I've checked that the translations aren't missing or attached to the wrong langcode, but all looked good.

So it does not look like the contextual filters are fixed, at least not during my testing, but it does fix the admin toolbar as expected.

If you know how to fix the contextual links, please by all means make an issue for it and post a patch, I'll gladly help test it out.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nikitas’s picture

Hi, for Drupal 8.8.5 i can confirm that #44 works as expected but i can not apply the #78 or any other (most recept) patch (2189267-100.patch or 2189267-98.patch).

pachabhaiya’s picture

Patch #44 works for me too on Drupal 8.8.6.

hardik_patel_12’s picture

Assigned: Unassigned » hardik_patel_12

Working on it.

hardik_patel_12’s picture

Assigned: hardik_patel_12 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.53 KB
new818 bytes

Solving test cases.

Status: Needs review » Needs work

The last submitted patch, 64: 2313309-64.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

istankevych’s picture

Drupal 8.8.6
I have multisite configuration.
First one use translations, but for second Language module is disabled.
With this patch (#44) I got next error (on site without Language module):

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\Core\Language\LanguageManager::setCurrentLanguage() in Drupal\language\ConfigurableLanguageManager::switchToUserAdminLanguage() (line 269 of core/modules/language/src/ConfigurableLanguageManager.php).
aimevp’s picture

StatusFileSize
new5.51 KB

I wanted to test the patch in #64 but immediately got the following fatal error:

Error: Using $this when not in object context in Drupal\language\ConfigurableLanguageManager::switchToUserAdminLanguage() (line 269 of core/modules/language/src/ConfigurableLanguageManager.php).

After comparing the code from the patch in #44 I noticed on lines 269 and 294 the variable "$languageManager" was replaced with "$this". Reverting it back to "$languageManager" (see attached patch) fixed the error but I'm not experienced enough to be sure if this is correct or if there's a reason why the original author of the patch used "$this".

I hope I've helped a little bit and didn't made it worse.

FYI: this patch was tested and works on a D8.9.3 install

jeroent’s picture

Status: Needs work » Needs review
StatusFileSize
new6.39 KB

Created a reroll for Drupal 9 + added trustedCallbacks method to ConfigurableLanguageManager.

Status: Needs review » Needs work

The last submitted patch, 68: 2313309-68.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

lubwn’s picture

Patch from #68 is working fine for me on 8.9.7, but contexual filters are still being translated and also tabs are still being translated as well. But admin menu is working nice now.

tunic’s picture

#71, local tasks (tabs) are being handled on this issue: #3054641: Local tasks should honor selected admin interface language (if set).

Also, it's interesting that the patch is working for you but tests for pacth from #68 reports 89 errors.

tunic’s picture

Errors from #68 don't seem random errors because I've scheduled a re-test and fails the same way.

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new6.41 KB
new2.94 KB

Handled CS messages.

Status: Needs review » Needs work

The last submitted patch, 74: 2313309-74.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new6.42 KB
new1.48 KB

Status: Needs review » Needs work

The last submitted patch, 76: 2313309-76.patch, failed testing. View results

nikitagupta’s picture

Status: Needs work » Needs review
StatusFileSize
new31.17 KB
new17.39 KB

Fixed the test case.

Status: Needs review » Needs work

The last submitted patch, 78: 2313309-78.patch, failed testing. View results

jhedstrom’s picture

Assigned: Unassigned » jhedstrom
+++ b/core/modules/contextual/src/Element/ContextualLinks.php
@@ -20,8 +20,12 @@ public function getInfo() {
+        ['\Drupal\language\ConfigurableLanguageManager', 'switchToUserAdminLanguage'],
         [$class, 'preRenderLinks'],
       ],
+      '#post_render' => [
+        ['\Drupal\language\ConfigurableLanguageManager', 'restoreLanguage'],
+      ],

I think all the tests failing were due to this. I don't think adding the language module to those tests is the proper fix, since the error being thrown in those tests will happen on any site that doesn't have the language module enabled.

Rather, I think only conditionally adding these pre/post render callbacks if the language module is enabled makes more sense. I'm going to take a look at that now.

nwom’s picture

StatusFileSize
new31.44 KB

#78 no longer applied against 9.2.x:

Checking patch core/modules/workspaces/tests/src/Functional/WorkspaceTest.php...
error: while searching for:
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['workspaces', 'toolbar', 'field_ui'];

  /**
   * {@inheritdoc}

Here is a re-roll. Nothing else was changed, so no need for an interdiff.

jeroent’s picture

Status: Needs work » Needs review
StatusFileSize
new8.98 KB
new19.33 KB

Well let's see if approach in #80 works.

jeroent’s picture

StatusFileSize
new8.98 KB
new437 bytes

Status: Needs review » Needs work

The last submitted patch, 83: 2313309-83.patch, failed testing. View results

jeroent’s picture

Status: Needs work » Needs review
StatusFileSize
new9 KB
new1.05 KB

Status: Needs review » Needs work

The last submitted patch, 85: 2313309-85.patch, failed testing. View results

jeroent’s picture

StatusFileSize
new9.01 KB
new661 bytes
jeroent’s picture

Status: Needs work » Needs review
jeroent’s picture

StatusFileSize
new16.48 KB
new25.04 KB
jeroent’s picture

StatusFileSize
new25.04 KB
new16.48 KB
jeroent’s picture

StatusFileSize
new25.35 KB
new16.79 KB

Added test coverage for contextual links, toolbar and links provided by user_toolbar().

jeroent’s picture

StatusFileSize
new16.3 KB
jeroent’s picture

Assigned: jhedstrom » Unassigned
jeroent’s picture

Status: Needs review » Needs work

The last submitted patch, 91: 2313309-91-test-only.patch, failed testing. View results

jeroent’s picture

Status: Needs work » Needs review
parisek’s picture

patch needs reroll

tunic’s picture

Issue tags: +Needs reroll

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

duaelfr’s picture

Issue tags: -Needs reroll
StatusFileSize
new25.57 KB
new16.71 KB

There you go!

ahmad abbad’s picture

+1

duaelfr’s picture

FYI, #100 patch applies on 9.2.x and 9.2.0-beta2 too.

anybody’s picture

Confirming RTBC for #100. Are we ready to set this RTBC?

chrisss’s picture

#100 works well, but there is one small issue still - for arabic (or any rtl language) the layout is still appearing in right to left format. it's a bit weird to have this when the text is in english. I was thinking of just overriding this in my theme with css but it might be a good idea to include this in the patch if it's going to be committed soon.

also maybe unrelated, but is there a similar patch or workaround to get the theme local task links/tabs to appear always in english as well?

thanks!

duaelfr’s picture

@chrisss Good point! We could add a dir attribute on the toolbar wrapper.

You'll find the patch you need for local tasks here: #3054641: Local tasks should honor selected admin interface language (if set)

chrisss’s picture

@DuaelFr I tried that actually but the issue is that the css currently gets the dir attribute from the parent element, so it's still overridden. Might need some css hacking.

Also thanks for the link!

phily’s picture

Patch #100 seems to be working well using Drupal 9.2.1 with French (admin + content) and English (content) languages.
Thanks

jeroent’s picture

Needs work for #104.

jeroent’s picture

Status: Needs review » Needs work
jeroent’s picture

Issue tags: +Bug Smash Initiative
jeroent’s picture

I was trying to fix #104 but it's not as simple as adding a dir attribute on the toolbar wrapper since styling is also added to the body element. e.g. in toolbar.module.css:

[dir="rtl"] body.toolbar-tray-open.toolbar-vertical.toolbar-fixed {
  margin-right: 240px;
  margin-right: 15rem;
  margin-left: auto;
}
parisek’s picture

I have conflict with LoginDestination which decorates ToolbarLinkBuilder class
https://git.drupalcode.org/search?search=LoginDestinationToolbarLinkBuil...

We probably cannot inject moduleHandler as it breaks compatibility with other modules

ArgumentCountError: Too few arguments to function Drupal\user\ToolbarLinkBuilder::__construct(), 1 passed in /Users/pari/Sites/drupal8/cimex/web/modules/contrib/login_destination/src/LoginDestinationToolbarLinkBuilder.php on line 41 and exactly 2 expected in Drupal\user\ToolbarLinkBuilder->__construct() (line 40 of core/modules/user/src/ToolbarLinkBuilder.php).

daften’s picture

@parisek

login_destination implements a decorator pattern, but in the wrong way. It is completely up to contrib to make sure the implementations are correct.

Side information: decorators should not extend the class they're decorating. They should implement the correct interface, implement all methods and use $this->inner->method calls for each method they're not decorating. This mistake is made often though, but it shouldn't block improvements from going in core imo.

seyfettinkahveci’s picture

StatusFileSize
new25.04 KB

Patch on #100 didn't work for core 9.2.5. The reason is due to the following 2 files
1. When I examined the patch, I saw that the line in the file "core/misc/cspell/dictionary.txt" was added to the core. I deleted these lines from patch.
2. I saw that the file "core/modules/toolbar/tests/src/Functional/ToolbarMenuTranslationTest.php" has changed. I manually adapted the patch according to the current file.

emek’s picture

StatusFileSize
new25.2 KB

In one of my environments I can't apply the patch in #114, I get the following message: "error: patch fragment without header at line 580: @@ -55,9 +55,8 @@ class ToolbarMenuTranslationTest extends BrowserTestBase {"

Since I could apply it in one of my other environments I was able to recreate it and now it works well.
The block for the file core/modules/toolbar/tests/src/Functional/ToolbarMenuTranslationTest.php was moved in the new patch.

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new25.5 KB
new218 bytes

Fixed the "custom command fail" issue.
Added word "entitynodedelete" in the cspell/dictionary.txt file. As per my understanding we can also ignore this word because it is on the test file however the related word 'entitynodeedit' also available in the dictionary file, on the basis of that I have added this word also, Please have a look and advise.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

emek’s picture

StatusFileSize
new25.53 KB

The patch in #116 didn't apply for me in 9.3.0
I recreated it, there was some functions that had some changes in core/modules/contextual/tests/src/Functional/ContextualDynamicContextTest.php and there was some changes in core/misc/cspell/dictionary.txt which caused the patch to not apply. I recreated the patch so it applies.
Unfortunately I couldn't create an interdiff for the changes.

Status: Needs review » Needs work

The last submitted patch, 118: 2313309-117.patch, failed testing. View results

akalam made their first commit to this issue’s fork.

gaurav_manerkar’s picture

Hi,

Which patch will work for 9.3?

unstatu’s picture

Status: Needs work » Needs review
StatusFileSize
new25.8 KB
new8.68 KB

I have improved a little bit the path #116:

- The sentences that come from configuration entities are also translated managed (for example the content types names)
- Checked the same permissions that are used in order to decide to show or hide the Administration pages languages option in the user profile (web/core/modules/user/src/AccountForm.php:255)
- Removed the LanguageInterface::TYPE_INTERFACE since it's the default one

akalam’s picture

I created a new MR based on #122 againt the branch 9.3.x https://git.drupalcode.org/project/drupal/-/merge_requests/1713

timohuisman’s picture

StatusFileSize
new27.43 KB

I've created a patch file from #126. We prefer a patch file because a MR url is moving target.

Status: Needs review » Needs work

The last submitted patch, 127: 2313309-127.patch, failed testing. View results

donapis’s picture

The patch in #127 is working for me.

cgoffin made their first commit to this issue’s fork.

cgoffin’s picture

StatusFileSize
new29.08 KB

I think there is still a problem with cache. When you change the language on the user profile page the toolbar isn't in the right language. I guess this is because the toolbar is cached based on the interface language and not on the user's admin language. I added a CacheContext for the preferred admin language and added it to the toolbar element.

alexpott’s picture

Title: Admin toolbar should always be rendered in the admin language (if set) » Admin toolbar and contextual links should always be rendered in the admin language (if set)

I think we should decouple the contextual link changes from the toolbar changes. I'm 100% sure that the toolbar should be in the user's admin language. Contextual links are a bit trickier because there are probably use-cases where the admin language might bit be the correct choice - that said writing that down I'm struggling to actually come up with a use-case so let's fix up the issue title to reflect what this patch is fixing.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new30.14 KB
new28.71 KB

Here's a patch that hopefully passes tests and works for the toolbar and contextual links. Will write up a comment with some additional thoughts later.

Status: Needs review » Needs work

The last submitted patch, 133: 2313309-2-133.patch, failed testing. View results

jeroent’s picture

Status: Needs work » Needs review
StatusFileSize
new32.31 KB
new3.46 KB

This should fix the failing tests.

yonailo’s picture

Hello,

I am experiencing issues when trying to apply this patch for keeping the english language in the form "media_library_add_form_upload".

I have a custom module with a form_alter, which does "$form = AdminLanguageRender::applyTo($form);"

But it seems that the AJAX callback is broken after this. I have been able to trace the issue and it seems that it is related with "Drupal\media_library\Form\AddFormBase::buildActions()". The "save select" action uses $value => $this->t('Save'), which is translated to "Enregistrer". After this, #pre_render seems to show the action button as "Save", but when clicking on save the triggeringElement() is not correctly detected.

I have changed the code of "buildActions" in order to use $value = 'Save', just for testing, and in this case everything works well.

Maybe this fonctionality is not thought to be used by $forms ? Is there any solution that would allow it to be used in forms, specially in forms with AJAX requests ?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

emek’s picture

StatusFileSize
new32.3 KB
new1.24 KB

I could not apply the patch in #135 on Drupal 9.4
Here is a new patch that applies.

simohell’s picture

[edit: my comment was addressed before I posted, hadn't refreshed the page]

emek’s picture

@simohell can you unhide my patch if it works for you, or should I upload it again?

ovanes’s picture

Hello

I have just tried to apply the patch from 135 comment but it happened that did not applied.
I am using Drupal core 9.4.x. It seems the reason way is that from that file dictionary.txt is missing that line entitynodeedit. It used be there in Drupal core 9.3.x but it seems it is not longer there in Drupal core 9.4.x
I have just added that to the patch and it applied for me.

P.S. if that line needs to be removed then we just need to remove it and the patch will apply again.

borisson_’s picture

Status: Needs review » Needs work

I've found a couple of nitpicks

  1. +++ b/core/lib/Drupal/Core/Cache/Context/AccountAdminLanguageCacheContext.php
    @@ -0,0 +1,51 @@
    +/**
    + * Defines the AdminLanguageCacheContext service, for "per admin language" caching.
    

    80 cols

  2. +++ b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualTranslationTest.php
    @@ -0,0 +1,117 @@
    +  protected $defaultTheme = 'classy';
    

    should this be olivero now?

  3. +++ b/core/modules/language/src/AdminLanguageRender.php
    @@ -0,0 +1,124 @@
    +  /**
    +   * The language manager.
    +   *
    +   * @var \Drupal\Core\Language\LanguageManagerInterface
    +   */
    +  protected $languageManager;
    +
    +  /**
    +   * @var \Drupal\Core\StringTranslation\TranslationManager
    +   */
    +  protected $translationManager;
    +
    +  /**
    +   * @var \Drupal\Core\Session\AccountInterface
    +   */
    +  protected $currentUser;
    

    only one of these has a short description, all of them should

  4. +++ b/core/modules/language/src/AdminLanguageRender.php
    @@ -0,0 +1,124 @@
    +  public static function applyTo(array $type): array {
    

    Needs @return documentation

akashkumar07’s picture

Status: Needs work » Needs review
StatusFileSize
new32.47 KB
new2.47 KB

This patch covers all the suggestions mentioned in #142.

proteo’s picture

Status: Needs review » Reviewed & tested by the community

I've been using the patch from #143 in a site with 5 languages for a couple of days and it works like a charm (Drupal 9.4.4).

Thank you!

jeroen dost’s picture

I used this patch (2313309-143.patch) on Drupal 9.4.4. The patch is successfully deployed, but it breaks the site:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: Class "language.admin_language_render" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 24 of core\lib\Drupal\Core\DependencyInjection\ClassResolver.php).
Drupal\Core\Controller\ControllerResolver->createController('language.admin_language_render:switchToUserAdminLanguage') (Line: 69)
Drupal\Core\Controller\ControllerResolver->getControllerFromDefinition('language.admin_language_render:switchToUserAdminLanguage') (Line: 760)
Drupal\Core\Render\Renderer->doCallback('#pre_render', 'language.admin_language_render:switchToUserAdminLanguage', Array) (Line: 363)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 85)
__TwigTemplate_64381f4af3c78cf09ccf72dcbfcb0abed14b23cd5876352e631da3cc7c98b69d->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/custom/front/templates/layout/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 162)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 163)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 46)
Drupal\redirect_after_login\RedirectMiddleware->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

(Removing only the patch restores the site, so it "must" be the patch.)
PHP version: 7.4.16

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 146: 2313309-127--3101231-19-combine.patch, failed testing. View results

guaneagler’s picture

StatusFileSize
new22.09 KB

Add the combined patch and add the enable option for the new feature.

borisson_’s picture

#146 and #148 are not needed here, if you need the combined patch it would probably be better to just put it in your own project. I also don't see the relation between both issues, they might touch the same code but they feel very different in scope and purpose.

It seems like the error in #145 is enough to actually move it back to NW.

@Jeroen Dost does a cache rebuild after applying the patch make the error go away? It sounds like the service definition can't be found but there is a definition in service.yml, if that fixes it we just need an update hook, otherwise we're going to have to figure out what else could be causing this.

markdc’s picture

#143 is working well for me. (D9.4.5 / PHP 8.0.22)

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new32.47 KB

Was hoping to get a response from @Jeroen Dost about their missing class error but I think that was just a cache problem somewhere.

Reuploaded the patch from #143 and setting it to needs review. Would like to see if this still passes tests.

ahmad abbad’s picture

StatusFileSize
new18.15 KB

Patch #152 is working with me

ahmad abbad’s picture

ameymudras’s picture

Status: Needs review » Reviewed & tested by the community

Tested on Drupal 10.1.x and php 8.1

- The issue summary is clear
- The patch applies cleanly
- Tested contextual links for multiple languages and works as expected
- #135 and #154 already includes screenshots so avoiding for repeatation
- No code issues noticed

Moving to RTBC

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record, +Needs release note
  1. +++ b/core/lib/Drupal/Core/Cache/Context/AccountAdminLanguageCacheContext.php
    @@ -0,0 +1,53 @@
    +  public function __construct(AccountProxyInterface $current_user) {
    +    $this->currentUser = $current_user;
    

    I'm pretty sure the API addition here (the new method on the configurable language manager) makes this only eligible for a minor release, so I think we should add return type hints and use constructor property promotion here.

  2. +++ b/core/lib/Drupal/Core/Cache/Context/AccountAdminLanguageCacheContext.php
    @@ -0,0 +1,53 @@
    +  public static function getLabel() {
    ...
    +  public function getContext() {
    ...
    +  public function getCacheableMetadata() {
    

    Let's add some return type hints here

  3. +++ b/core/misc/cspell/dictionary.txt
    @@ -432,6 +432,8 @@ enim
    +entitynodedelete
    +entitynodeedit
    

    Are these still needed, I don't see them anywhere else in the patch

  4. +++ b/core/modules/contextual/contextual.module
    @@ -174,13 +174,15 @@ function contextual_contextual_links_view_alter(&$element, $items) {
    +    $args['metadata'] += ['langcode' => $langcode, 'admin_langcode' => $admin_langcode];
    

    nit >80 here on an array

  5. +++ b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualTranslationTest.php
    @@ -0,0 +1,117 @@
    +    $this->clickContextualLink('article.node', $edit_translation);
    

    Whilst I know this is testing what we want, is there any way we can do it without using a WebDriver based test, which are typically slow and flaky?

  6. +++ b/core/modules/language/src/AdminLanguageRender.php
    @@ -0,0 +1,131 @@
    +  /**
    +   * The language manager.
    +   *
    +   * @var \Drupal\Core\Language\LanguageManagerInterface
    +   */
    +  protected $languageManager;
    +
    +  /**
    +   * The string translation service.
    +   *
    +   * @var \Drupal\Core\StringTranslation\TranslationManager
    +   */
    +  protected $translationManager;
    +
    +  /**
    +   * The current user.
    +   *
    +   * @var \Drupal\Core\Session\AccountInterface
    +   */
    +  protected $currentUser;
    ...
    +  public function __construct(LanguageManagerInterface $languageManager, TranslationManager $translationManager, AccountInterface $currentUser) {
    +    $this->languageManager = $languageManager;
    +    $this->translationManager = $translationManager;
    +    $this->currentUser = $currentUser;
    

    Because there's an API change here (the new method on ConfigurableLanguageManager), this is likely 10.1 only.

    So let's use constructor property promotion here.

  7. +++ b/core/modules/language/src/AdminLanguageRender.php
    @@ -0,0 +1,131 @@
    +  public function switchToUserAdminLanguage(array $element) {
    ...
    +  public function restoreLanguage($content, $element) {
    

    Let's add some type hints and return types here

  8. +++ b/core/modules/language/src/AdminLanguageRender.php
    @@ -0,0 +1,131 @@
    +  public static function trustedCallbacks() {
    

    Let's add a return type hint here for : array

  9. +++ b/core/modules/language/src/ConfigurableLanguageManager.php
    @@ -235,6 +235,18 @@ public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE) {
    +  public function setCurrentLanguage(LanguageInterface $language, $type = LanguageInterface::TYPE_INTERFACE) {
    +    $this->negotiatedLanguages[$type] = $language;
    +  }
    

    Shouldn't we be adding this to the interface too?

    Also, let's add a string type hint for $type and either make this method fluent (return $this) or add a void return typ

  10. +++ b/core/modules/toolbar/toolbar.routing.yml
    @@ -4,3 +4,5 @@ toolbar.subtrees:
    +  options:
    +    _admin_route: TRUE
    

    This isn't necessarily so - see #1044090: Enable toolbar for authenticated users also, so that non-admin users can use shortcuts as well

  11. +++ b/core/modules/user/src/ToolbarLinkBuilder.php
    @@ -21,14 +23,24 @@ class ToolbarLinkBuilder implements TrustedCallbackInterface {
    +  public function __construct(AccountProxyInterface $account, ModuleHandlerInterface $moduleHandler) {
         $this->account = $account;
    +    $this->moduleHandler = $moduleHandler;
    

    we can use constructor property promotion here.

    I was going to ask if we need to do a deprecation dance here, but there's no sub-classes in contrib according to https://git.drupalcode.org/search?search=ToolbarLinkBuilder&group_id=2 so we can probably just go with a change notice

Tagging for release not and change record

borisson_’s picture

Looks like more work is also needed to support layout builder sections/blocks (in \Drupal\layout_builder\Element\LayoutBuilder::buildAddSectionLink / \Drupal\layout_builder\Element\LayoutBuilder::buildAdministrativeSection, I think).

Is there a way to add a test that allows us to test if other frontend UI items are also translated?

leo liao’s picture

StatusFileSize
new34.19 KB

Add the combined patch and add the enable option for the new feature.

michaelsoetaert’s picture

StatusFileSize
new34.27 KB

I've rerolled the patch in #158 so that it applies on the latest versions (10.1.x, 10.0.4 & 9.5.4).

n.ghunaim’s picture

StatusFileSize
new32.48 KB

I implement a small fix to patch #152, I assigned a NULL value to moduleHandler on the _construct function
public function __construct(AccountProxyInterface $account, ModuleHandlerInterface $moduleHandler = NULL) {
in ToolbarLinkBuilder.php file as I get this error when running the patch.

The website encountered an unexpected error. Please try again later.
ArgumentCountError: Too few arguments to function Drupal\user\ToolbarLinkBuilder::__construct(), 1 passed in /app/docroot/modules/contrib/login_destination/src/LoginDestinationToolbarLinkBuilder.php on line 41 and exactly 2 expected in Drupal\user\ToolbarLinkBuilder->__construct() (line 41 of core/modules/user/src/ToolbarLinkBuilder.php).
joao.ramos.costa’s picture

StatusFileSize
new32.48 KB
new4.36 KB

Rerolled #152 for 9.5.4 .

joao.ramos.costa’s picture

StatusFileSize
new32.51 KB

Fixes #161 patch.

wylbur’s picture

The patch in comment #162 applied cleanly to 9.5.5

leo liao’s picture

StatusFileSize
new32.64 KB

Add the combined patch and add the enable option for the new feature. for 9.5.5

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

snehauskoim’s picture

Patch #162 has applied but contextual links are totally disappeared in some cases in layout builder

kpaxman’s picture

I see #149 says that #146 and #148 are not needed, and #164 seems to be an extension of those. Should anyone outside of the people posting those patches be using them? I'm not sure what the point is of an enable option, given that is just honoring existing config.

DieterHolvoet made their first commit to this issue’s fork.

dieterholvoet’s picture

I started a new branch based off 11.x with the patch from #152 and the feedback from #156. Only the refactoring of the WebDriver based test hasn't been done yet. Let's stop posting patches now to avoid confusion, especially patching combining multiple issues. These don't belong here.

Regarding the typehint related feedback in #156: I'm not sure we should add typehints if the parent class hasn't decided on a typehint. For example, CacheContextInterface::getLabel currently has string documented as return type, but we also have to account for instances of TranslatableMarkup there. How exactly that should be done hasn't been decided yet, so we shouldn't either in the child class.

Regarding #160, there's a separate issue for that problem in the login_destination queue: #3261748: LoginDestinationToolbarLinkBuilder implements the decorator pattern in a wrong way.

timohuisman’s picture

StatusFileSize
new43.88 KB

This patch represents the current state of MR created in #170. We prefer patch files as long as the merge request urls are considered dangerous, see https://github.com/cweagans/composer-patches/issues/347.

timohuisman’s picture

StatusFileSize
new43.88 KB

This time with a valid patch file extension...

joao.ramos.costa’s picture

HI @timohuisman,

thank you for the heads up!

recrit’s picture

StatusFileSize
new33.06 KB

I'm not sure what #173 was, but it was not created with https://git.drupalcode.org/project/drupal/-/merge_requests/4604.diff.
Attached is the new 11.x MR 4604 at commit 7975cb1f.

tvalimaa’s picture

Updated:

#175 gave me error but I got it working. This patch didn't solve my toolbar problem

johnshortess’s picture

The patch in #173 was working for us in 10.1.x. But it no longer applies in 10.2.0, nor does the patch from MR 4604. I'll take a look to see what's changed, but it may be several days until I have time.

linhnm’s picture

StatusFileSize
new22.88 KB

Rerolled the patch #173 for Drupal 10.2.0

linhnm’s picture

StatusFileSize
new32.53 KB

Fixes #178 patch

mathieu.h’s picture

#179 works, thx!

andrew.wang’s picture

I didn't review the code but just wanna report that #179 works well for me on a big site running Drupal 10.2.1!

carlos romero’s picture

manikandank03’s picture

Patch #179 works fine in Drupal 10.2.2 with PHP 8.2.

zeip’s picture

The patch in #179 fixed this for us. The merge requests !4604 and !6351 both include the patch file, which shouldn't be included in the MR's but at least !6351 looks otherwise ok.

smulvih2’s picture

#179 works for me in Drupal 10.2.2 using PHP8.1.

matthiasm11’s picture

+1 for #179. Drupal 10.2.6 using PHP 8.2.

carlos romero’s picture

andrew.wang’s picture

Status: Needs work » Needs review

sokru changed the visibility of the branch 2313309-admin-toolbar-language to hidden.

sokru changed the visibility of the branch 2313309-9.3 to hidden.

sokru changed the visibility of the branch 2313309-179-11.x to hidden.

sokru’s picture

Status: Needs review » Needs work

I hide all other branches than MR 4604. I rebased it and addressed the parts of feedback from #156 that where missing, except for
- Typehints not done per #170.
- #156.5: Is still open question.
- #156.8: Instead of adding typehint, made https://www.drupal.org/node/3349470, that seems still need a work with tests (AutowireTest)

This still needs work:
- Fix issues on MR 4604
- Needs change record
- Needs release note

sokru’s picture

Issue summary: View changes
Status: Needs work » Needs review

Fixed the tests and created a draft for change record and release notes.

smustgrave’s picture

Status: Needs review » Needs work

@sokru thanks for hiding the old MRs, also good to hide all patches since those aren't needed anymore and the bot could pick them up.

Left some comments on the MR.

sokru’s picture

Status: Needs work » Needs review

All the feedback has been addressed.

carlos romero’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs release note

Feedback does appear to be addressed

But CR https://www.drupal.org/node/3456217 is empty

LRoels changed the visibility of the branch 2313309-9.3 to active.

LRoels changed the visibility of the branch 2313309-admin-toolbar-should to active.

LRoels changed the visibility of the branch 2313309-admin-toolbar-language to active.

LRoels changed the visibility of the branch 2313309-admin-toolbar-language to hidden.

LRoels changed the visibility of the branch 2313309-admin-toolbar-should to hidden.

LRoels changed the visibility of the branch 2313309-9.3 to hidden.

sleitner’s picture

Status: Needs work » Needs review
ronttizz’s picture

Tbh I am not entirely sure do I understand the whole process and issue but I tested this with Umami. The site has english and spanish out of the box. These are my findings.

I selected spanish as my admin preferred language.

For the language change block on Umami site it seems that these are using spanish

But "Umami Home Banner" block these are not translated.

Tbh, I am not sure are these in the scope of this issue.
Otherwise it seems that all the top admin nav/toolbar is respecting the admin language and they are spanish even though I am browsing the site in english.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record +Needs Review Queue Initiative

Thanks @sleitner for updating the CR

@ronttizz your issue sounds like a block issue. Would recommend searching the issue queue to see if there is a similar ticket and leave a comment. Sometimes a simple comment of "saw this today on 10.3 while testing xyz" could bring people back to it. Joy of open source! haha

Feedback on the MR here appears to be address

nod_’s picture

This looks good to me. Anyone tried it with navigation module? Make it a follow-up if it doesn't work we don't need to solve it here, This has always annoyed me so big +1 to this :)

irafah’s picture

After updating the site from version 10.3.1 to 10.3.2 and applying patch #179, the site went down - `The website encountered an unexpected error.`
The main error:

 Error: Class "Drupal\language\AdminLanguageRender" not found in /app/web/core/modules/language/language.module on line 148 #0 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(552): language_element_info_alter(Array, NULL, NULL)

What is weird is that the class is indeed there and I can even access it by clicking ctrl+click over the class, which shows that it does find it

Has anyone faced anything like this with core 10.3.2?

frontmobe’s picture

I applied the patch on a site that was already running Drupal 10.3.2 (php 8.2.13, Apache 2.4.54) and could not replicate the behaviour that was described in #209, the patch worked as expected on this install.

Specifically I did the following:
- put the patch link in the "patches" section of the root composer.json and ran composer install, the patch (in #179) applied cleanly.
- logged into the site as an administrator and opened a page in dutch, the admin had dutch set as the "Administration pages language" on his profile, the administration menu items in the toolbar showed in dutch, as expected.
- changed the "Administration pages language" in the admin profile to english and opened the same dutch page, the administration menu links now showed in english, as expected.

Based on this behaviour it seems that the patch functions correctly on this install running Drupal 10.3.2, I also checked the logs for anything unusual but all was working perfectly fine. Hope this helps!

irafah’s picture

I started the update over and this time it worked as expected. Might have been a local issue
Thanks for looking

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I left some review comments on the MR that should be addressed.

sokru’s picture

Status: Needs work » Needs review

Resolved the threads created by @alexpott and created a follow-up issue for Navigation module #3472043: [PP-1] Navigation module should honor admin language on frontpage and node route.

smustgrave’s picture

Status: Needs review » Needs work

Gave it another lap but mostly small stuff.

Looking at the CR they may need a little work, especially https://www.drupal.org/node/3456217 should include the service being called in the example.

sokru’s picture

Status: Needs work » Needs review

Addressed the latest feedback. However I didn't modify the change record, since I could not think up of any useful example and I did not find any other change record which would give an examples of new services. Given the age of this issue I think the CR can be updated later if someone comes up with any useful examples.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new6.32 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

needs-review-queue-bot’s picture

Status: Needs work » Needs review

False positive

carma03’s picture

Confirming patch #179 works on D10.2.7 and PHP8.2.

szato’s picture

I am using MR diff to patch D10.3.6, php 8.3. Works.

frontmobe’s picture

I performed the same routine as I used in #210 to check the patch in #179, this time using Drupal 10.3.6 and PHP 8.3.13. The patch works as expected.

sagarmohite0031’s picture

Hello,
Getting error while applying Mr
attaching screenshot

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

yevko’s picture

MR doesn't apply on 11.1.x

sokru’s picture

Status: Needs work » Needs review
kekkis’s picture

Thanks @kallevu for the update on the MR! I tried working on that on the global contrib weekend but failed miserably. It would be nice if this could move forward now that it seems to produce green results too.

gillesv’s picture

I can confirm what @yevko's saying: the MR does not apply on 11.1.x

This change is rejected on "modules/language/language.module", probably because the dev-version of 11 looks quite different there:

--- modules/language/language.module
+++ modules/language/language.module
@@ -19,6 +19,7 @@
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\language\AdminLanguageRender;
 use Drupal\language\Entity\ContentLanguageSettings;
 use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
 use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
sokru’s picture

The MR is not supposed to be applied to 11.1.x but on 11.x branch. If this gets accepted to 11.x then we can create a MR for 11.1.x.

smustgrave’s picture

Status: Needs review » Needs work

Resolved most threads but left just a few more.

Question what happens if admin_langcode is not included.

If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

robin.houtevelts made their first commit to this issue’s fork.

robin.houtevelts’s picture

StatusFileSize
new548.17 KB

I've addressed the threads in the MR.

"What happens if admin_langcode is not set?"

Consider the following setup:

  1. Site default language: EN
  2. Current interface language: NL
  3. User's admin language: set to - No preference -

Currently:

  1. AccountAdminLanguageCacheContext calls Account::getPreferredAdminLangcode(fallback_to_default: TRUE)
  2. AdminLanguageRender calls Account::getPreferredAdminLangcode(fallback_to_default: FALSE)

This difference results in the toolbar and contextual links rendering in NL, while the user.admin_language cache context falls back to EN. This inconsistency indeed needs to be addressed.

AccountAdminLanguageCacheContext needs to accurately reflect the user's actual setting. In this case - No preference -, so it should use fallback_to_default: FALSE instead of TRUE.

(👆This still needs to happen.)


While testing, I noticed some contextual links were translated and others were not. The tests pass, but I'm not confident.
I'm including a recording.

weseze’s picture

Any chance of a patch against latest D11 stable release?
I could not get it working based on the MR diff/patch, tried to fix it manually but I was out of my depth there...

sleitner’s picture

Rerolled

sleitner’s picture

Status: Needs work » Needs review

Rerolled and removed not matched ignoreErrors

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

sleitner’s picture

Status: Needs work » Needs review

Rerolled

hmdnawaz’s picture

StatusFileSize
new37.95 KB

patch form MR for 11.2

smustgrave’s picture

Status: Needs review » Needs work

This is looking good but see we had to update a lot of tests across a number of modules. Makes me think this could be a BC, can add a test where admin_langcode is omitted to show it won't break,.

sleitner’s picture

Status: Needs work » Needs review

Added a test which tests the contextual toolbar with and without admin language set.
Added a theme cache context to fix the issue @robin.houtevelts mentioned in #230.

sleitner’s picture

Bumped to 11.4

sleitner’s picture

Rerolled again with performance test limbo. Please review.

tuutti made their first commit to this issue’s fork.

almador’s picture

Recently updated Drupal 9.5.11 to 10.6.1

After applyin the patch #179 this WSOD error appears on many pages:

ArgumentCountError: Too few arguments to function Drupal\user\ToolbarLinkBuilder::__construct(), 1 passed in /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 261 and exactly 2 expected in Drupal\user\ToolbarLinkBuilder->__construct() (line 27 of core/modules/user/src/ToolbarLinkBuilder.php).

sleitner’s picture

Rerolled again with performance test limbo. Please review.

dench0’s picture

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

sleitner’s picture

Status: Needs work » Needs review

Rerolled again. Please review.

sleitner changed the visibility of the branch 2313309-179-11.x to active.

sleitner changed the visibility of the branch 2313309-11.x to hidden.

sleitner’s picture

Status: Needs review » Needs work

maurizio.ganovelli changed the visibility of the branch 2313309-admin-toolbar-language to active.

idflood made their first commit to this issue’s fork.

idflood’s picture

Sorry for the wrong merge request. Patch #244 still applies cleanly on D11 but I had another issue which made it fail. Now that it applied cleanly it works as expected.

sleitner changed the visibility of the branch 2313309-admin-toolbar-language to hidden.

recrit’s picture

The patch in #244 is no longer applying to 11.3 due to the changes in the `core/profiles/demo_umami/tests`. For that reason, I have rolled a D11.3 patch that does not have the changes to `core/profiles/demo_umami/tests` so that it applies cleanly to D11.3.

I would have contributed to the MR, but the MR 6351 appears to have erroneous changes most likely due to some rebasing. It is showing a lot of unrelated changes.