8

So for this site I'm building I need to be able to do the following.

  1. When user views the site in English show all English articles
  2. When the user views the site in Dutch, show all Dutch articles - but also the untranslated English ones
  3. When the user views the site in German, show all German articles - but also the untranslated English ones.

The contextual filter, 'Content translation: Language' only allows to put in one value. That is either a language specified, or all.

But in my case it would be required to be able to set for instance "en+nl" or "en+de". Like one can do with taxonomy 'Has Taxonomy', I would like something like 'Has Language'.

4 Answers 4

3

I solved this task like so:

  • For "When the filter value is not available", select option "Provide default value".
  • then use "PHP Code" as the value for "Type"
  • the actual PHP code I added is as shown in the screenshot below:

enter image description here

2
  • Adding php on a view ? That is ugly..... It solve the problem but I do not think this is a good idea. Dec 2, 2015 at 19:05
  • This may be hackish but this exactly got me what is needed for a slightly different requirement - one view page, with language prefixes: site.com/en and site.com/ja ... When user is on EN, shows all content with EN content; when switched to JA interface, shows only content with JA translation. Thanks! Jan 22, 2018 at 13:36
2

One solution would be to use field translation:

  1. Set "Enable language fallback" to active in the entity translation configuration page.
  2. Set the view to use the current user language (Advanced>Other>Field Language).

Done.

2
  • can't see a "Enable language fallback" option on that page. need to install Entity translation module before, I think...
    – headkit
    Aug 13, 2012 at 9:15
  • how else would you access the modules configuration page? I should have pointed that out more clearly though, so thanks for adding that information.
    – cjoy
    Aug 14, 2012 at 16:40
1

I guess you need this module: https://www.drupal.org/project/select_translation

it provides language fallback functionality for nodes translated with Content Translation (not Entity translation) inside views listings. This is an alternative to the Views "Field Language" option which would not work for nodes translated with Content Translation.

1

To have a View with a default language fallback if a node translation doesn't exist and then show the default language one, just ensure UNCHECK:

X When needed, add the field language condition to the query

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.