Problem/Motivation
At the moment, the Block fetches the translated field from the entity using the getCurrentLanguage() function. The problem being that the default for this is the interface language. If you've defined a separate language for content, it won't work.
My use case being that the sites interface is always in English, but the content can be in many different languages.
Proposed resolution
There are two options I can see.
- Always use the content language. This feels safe, the block is content after all.
- Provide an option in the block management screen that asks if you want the content language or interface language.
I've provided a patch for option 1. It also adds the language to the cache contexts. This needs to be done regardless.
Remaining tasks
Decide on the approach to take
Commit.
User interface changes
Depends on approach
API changes
Depends on approach
Data model changes
Depends on approach
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | Screenshot 2026-08-07 at 09.23.31.png | 174.88 KB | joelpittet |
| #20 | Screenshot 2026-08-07 at 09.26.18.png | 181.22 KB | joelpittet |
| #14 | fieldblock-content-lang_3173729_3.patch | 1.4 KB | gareth.poole |
| #2 | fieldblock-content-lang_3173729_2.patch | 1.41 KB | danielveza |
Issue fork fieldblock-3173729
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
Comment #2
danielvezaComment #3
igork96 commentedI tested this and can't reproduce it with the latest version 8.x-2.0-alpha5 and:
1. Created a node in en
2. Translated in de
3. Put the field body as a block
4. Getting different content (translation) when I visit en/de site.
Can you please give more info on how to reproduce it or it's maybe fixed in the recent releases...
Comment #4
danielvezaI haven't used this module in awhile now - if the issue can no longer be reproduced this can be closed
Comment #5
igork96 commentedThanks, closing this until we get more info.
Comment #8
stewestI'd like to open this up again as I can reproduce the issue.
We're using Drupal 9.5.5 with the Sector Distribution.
When I add a field as a block, like the subtitle or banner image field (all with translations enabled) and using Content language (instead of interface language), when I add a translation, I expect to see the translated content on the page, but I see the original languages content.
The patch at https://www.drupal.org/project/fieldblock/issues/3173729#comment-13840638 works for me.
Comment #10
stewestLooks like we need to update the patch for 2.3
Comment #14
gareth.poole@stewest updated patch for 2.3
Comment #16
stewestI've tested this updated patch and it works
rather than the old patch "Use content language rather than interface": "https://www.drupal.org/files/issues/2020-09-28/fieldblock-content-lang_3..."
Comment #18
joelpittetJust moving this to the dev branch version.
Comment #19
joelpittetThanks everyone for the testing, updated patches, and digging into this over the years. I think we have a solid picture now of why this fix is the right one.
Core's parameter converters already hand the block the content-language translation — both
EntityConverterandEntityRevisionParamConverterresolve the entity translation through the content language. SogetTranslatedFieldFromEntity()was undoing the translation core had already selected, switching it back to the interface language. UsingTYPE_CONTENTisn't just the safer option, it matches how the entity arrives in the block in the first place.That makes me think we can close out the second proposed option, a per-block content/interface language toggle. If someone has a use case for it later, it feels better suited to a separate feature request.
I also looked at the
EntityAdapter::createFromEntity()+setContext()handling. It works, if indirectly:setContext()changes the parent rather than the field values, andEntityViewBuilder::viewField()builds from$items->getEntity(), so the translated parent entity is what determines the rendered value.I've added regression coverage that negotiates the interface and content languages separately: interface fixed to English, content taken from the URL prefix. That's the configuration where the two can actually disagree; with the default setup the content language follows the interface language, which helps explain why this was difficult to reproduce earlier in the issue.
The tests cover three cases:
languages:language_contentcache context.Worth noting that the two lines of the patch belong together.
/node/1and/de/node/1resolve to the same route with the same parameters, so theroutecontext alone doesn't vary per language — the content language context is what lets the block cache correctly. The translation test requests English before German for that reason, and there's a note on the method so the ordering doesn't get rearranged later.AI disclosure: I used AI to help generate the tests. I reviewed and directed the resulting code, including its style and approach. Used DDEV locally to manually test to make sure I didn't introduce a regression.
Comment #20
joelpittetMy manual test scenario: interface language fixed to English via
language-selected, content language from the URL prefix... the only configuration where the two can disagree. Article has a translatablefield_subtitle, hidden from the node view display so the field block is the only thing rendering it, placed in Olivero's Content Above region.German field block before fixes, after node/1 cached as English:

German field block after fixes, after node/1 cached as English:
