Scenario: I'm building out a multilingual site in Drupal 8. As the site contains a blog, which is obviously built on a view, this throws up a couple of interesting issues. The blog author is fluent in two languages; sometimes, he will post in English (for the wider audience) and occasionally in his native Italian (maybe for a homeland-specific post). Either way, I'd still like the blog to display an entry for each post, so there are no omissions regardless of language.
So, this poses the question - if any post could be in either language, how do I get the blog to be shown in the user-selected language, but show any/all posts written in the other language if they are untranslated (i.e., fall back to Italian if no English translation is available, and vice versa if viewing in Italian)?
A standard blog view, based on a
Blog content type and view would be nominally be filtered thus:
Content: Type (= Blog) &
Content: Publishing status (= Yes) and ordered with:
Content: Authored on (desc)
The problem with this unaltered approach is, Views will pull out all blog posts regardless of translation. So essentially, if your last post is translated into two languages, both translations will appear and count as 2 of your (say) 10 most recent posts, which is effectively duplicate content - at least, to the reader.
Solution: Prevent the duplicate appearance of nodes by setting a filter on the view to show only the default translation. Then, request that the view be rendered only in the current language, which will set the view rows as such but use the fallback language if there's no translation.
So, the technical steps for this: Add a new filter by clicking Add and typing "def" into the search field and selecting the "Default Translation" filter under the "Content" category. As an entity can only have one default translation, this ensures they're only shown once. Secondly, set the rendering language preference under "Language" to "Interface text language selected for page". This will attempt to display the views row in the current language and fall back if that's not available.