When building a multilanguage project in Drupal 8+, you need to know some important steps. One of them is Drupal Views multilanguage configuration.
Drupal Views are a flexible tool and as such they offer you many ways to display your content. The downside is, that by default the view output on multilanguage projects will give you all translations of your contents in the view, which means there might be duplicate results.
Typically you want view to only show contents in the selected language (from your language selection block).
In my example I configured the project to use the content language for language selection. The following also works when using interface language. We won't go deeper into the differences here, but typically interface language is the language for the administration area like admin menu, tabs, field labels etc. whereas the content language is the language the contents are translated into. A good example is, that you may administer the website in English, but contents can be translated into Chinese (which you might not be able to understand).
So typically for the views content language is what you want. But there may be different cases.
Okay, let's do it!
After setting up the view, you need to do two things:
- Add a filter criteria: Default Translation: True
- Select Rendering Language: Content language selected for page (or interface language if that's what you need)
This is what the result should look like (arrows):
Step 1: Add the filter criteria:
Step 2: Select the Language > Rendering Language:
Save the view, now you should only see the expected results. When changing the language via the language switcher block, the results are shown only in the selected language.
Note: This configuration will also render the language neutral content, which is typically expected!
If you'd also like to exclude the language neutral content, use the Translation language: Content language selected for page filter instead of the Default language: True filter!
Warning: No setting inheritance from master display
Take care! As I had to find out, the Translation language setting isn't inherited from the master display, and so you have to set it on each view display individually (which is bad UX / SBX). I created an issue for that: https://www.drupal.org/project/drupal/issues/3432646