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?
Comment | File | Size | Author |
---|---|---|---|
#4 | drupal-menu-cache-language-content-3043226-3.patch | 2.17 KB | joshf |
#2 | drupal-menu-cache-language-content-3043226-2.patch | 732 bytes | joelstein |
Comments
Comment #2
joelstein CreditAttribution: joelstein at On Fire Media commentedSame issue here. Here's a patch which includes the "languages:language_content" cache context.
Comment #4
joshf CreditAttribution: joshf at Third and Grove commented#2 fixes the issue for me; thanks!
Attached patch includes @joelstein's fix and should fix some of the test failures.
Comment #8
firewaller CreditAttribution: firewaller commentedFYI 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.
Comment #12
AnybodyComment #15
missvengerberg CreditAttribution: missvengerberg at 1xINTERNET commentedWe 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.