Problem/Motivation
Rendered entity in view doesn't respect the views row rendering language.

Views setup:
- Create a view of entity type media (using media 8.x-1.7 atm)
- Add a display of type page and use the table format
- Rendering Language: Content language of view row
- Add field of type Rendered entity and select a view mode. Media: Rendered entity (view mode: field_preview)
- Add a exposed filter for translation language
Entity (media) setup:
In the view I show media entities of the type 'media collection'.
Media collection has a entity reference to the media entity of type 'image' (for the teaser image of the collection)
- Set the media entity to translatable
- Select all fields to be translatable
- On the media entity 'image' set the field that contains the image to translatable (including file, title, alt)
Proposed resolution
Pass the entity language id to the view builder in the render function of the plugin.
Drupal\views\Plugin\views\field\RenderedEntity on line 115:
$build += $view_builder->view($entity, $this->options['view_mode']);
should be:
$build += $view_builder->view($entity, $this->options['view_mode'], $entity->language()->getId());

Comments
Comment #2
jens.de.geit commentedComment #3
lendudeFix makes sense, lets see what the testbot thinks....
Comment #5
lendudeTestbot doesn't like spaces in filenames....
Comment #7
mbovan commented#5 works for me on D8 8.5.3.
Setting to needs work because of missing tests.
Comment #9
berdirReroll, still needs tests.
Comment #10
berdirComment #11
rollingnet commentedI can confirm that the patch solves the issue.
Tested with Media Library view on Drupal 8.7.1
A reroll of the patch should be done with the latest version of Drupal.
To me, it's ready to be marked as "fixed".
Comment #12
anybody@rollingnet: No this is not fixed, because the fix has not been committed. But of course you can add your RTBC ;) And yes, this important patch fixes it.
@Berdir: Thank you so much - I had to search a lot to find this issue which was a major problem in several multilang D8 projects using rendered entity fields. Simply fix, HUGE improvement!
Confirming RTBC for #9. I tested it in 8.7 and 8.8.
Comment #13
anybodyComment #14
anybodyComment #15
anybodyHere's a similar patch with tests included: #3045344: Views Rendered Entity field ignores the configured rendering language of the view display. I closed it as duplicate and informed the patch author to have a look at this issue. Would be lovely to see this committed to 8.8.x this way.
Comment #16
tstoecklerMarking needs work, as we need to provide an automated test that proves the current problem and that the fix fixes it. (See also #7 and #9).
Comment #17
godotislatePatch for failing test.
Comment #18
godotislatePatch from #9 with tests.
Comment #19
godotislateComment #20
mbovan commentedComment #21
mbovan commentedTested locally and #18 works great.
Comment #22
gábor hojtsyThis of course works fine with Rendering Language: Content language of view row, does it work with other settings? The hardwired entity language getid makes me wonder. I looked at the tests and it is well tested with various other language rendering modes, so looks good. Will ask @plach for second opinion just to make sure I am not missing anything. This looks almost too simple a fix for such a bad bug :D
Comment #23
plach@Gábor Hojtsy:
The fix is good:
$entity->language()->getId()is the language of the entity translation instantiated using the configured entity translation renderer, so all cases are covered.Comment #24
plachBugs are fixed in the stable branch first.
Comment #27
plachCommitted 6dc692b and pushed to 8.8.x and backported to 8.7.x. Thanks!