Background:

The website we are building will support two different languages, and all the content is being translated so there are versions for both.

However, we have not turned on interface translation, since we want the drupal interface to remain in English, as that is what the site editors are most comfortable using.

The Problem:

When switching to the alternate language of a page, the menu blocks items are remaining in English, and don't change unless you clear the render cache.

The Cause:

Despite the menu items being content that is translated using content translation, the rendered menu blocks are being stored in the cache using the interface language instead of the content language, such as:

cid: entity_view:block:site_name_main_menu:[languages:language_interface]=en:[route.menu_active_trails:main]=menu_trail.main|menu_link_content:8c16c3a4-f165-4ea4-b2b4-07a1cee8e592|:[theme]=site_name:[user.perm-AjQCijrXHvxvgiuYXJCT4T4GgXa1tNWosi6GEgeN5Y

The Solution?

Could we switch menu blocks over to using the content language instead of the interface language? Or should we store both, so a rendered copy of the block is stored for each interface/content language combination?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikemccaffrey created an issue. See original summary.

joelstein’s picture

Same issue here. Here's a patch which includes the "languages:language_content" cache context.

Status: Needs review » Needs work

The last submitted patch, 2: drupal-menu-cache-language-content-3043226-2.patch, failed testing. View results

joshf’s picture

#2 fixes the issue for me; thanks!

Attached patch includes @joelstein's fix and should fix some of the test failures.

Status: Needs review » Needs work

The last submitted patch, 4: drupal-menu-cache-language-content-3043226-3.patch, failed testing. View results

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.

firewaller’s picture

FYI I was having this same issue, where menu blocks were caching the first language I visited and then needed a cache clear to show the next language. Unfortunately, the issue is then reversed.

However, I resolved this by enabling the "URL" detection method in "Interface text language detection" (/admin/config/regional/language/detection) settings after the previously enabled "Account administration pages" detection method. I believe the reason for this is that although we wanted the Admin interface to always be the sites default language (English), the menus are treated as interface and not content.

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.

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.

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.

Anybody’s picture

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.

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.

missvengerberg’s picture

We were having this issue with Drupal 9.4.8 and PHP 8.1. Applied patch #3 and it's working fine now. Thanks so much for the patch.

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.