how to filter views result to the current language nodes

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
monti's picture

I use a view to show a list of nodes flagged by a global flag (any user, any language) and would like to return only current language related nodes. any idea?

Comments

Try setting your filter to -

nonsie's picture

Try setting your filter to - Node translation: Current user's language

Node translation

mudasirweb's picture

I am not getting this filter option in view, even I have enabled entity translation module. Needs help please?

so simple ...

monti's picture

how did i miss it ?

indeed:
Node translation: Language = Current user's language

sometimes you look for a solution under the floor while it is sitting calmly right in front of you.

works like a charm. thanks !

rfay's picture

Just a note for anybody following up on this... The "Current user's language" is the language that a particular authenticated user has set in the user settings. It's not the same as the current browser or site language.

Current user's language

Kristen Pol's picture

From my research, this was not based on the user profile language setting (which it sounds like it should be based on the name).

This is a bit confusing as I found when writing the book for D7 i18n (and not documented as far I as I could tell). I got the low-down from looking at the code and chatting with Gábor Hojtsy. It goes something like this:

Do you have Entity Translation module installed?

1) No. Current user's language ("content language") is the same as the "interface language" which is determined by the interface language negotiation/detection settings.

2) Yes. Current user's language ("content language") is determined by the content language negotiation/detection settings (which may or may not be set to the same settings as the interface language negotiation/detection settings... depends on how you configure it).

Note that other modules may also choose to implement the "content language" behavior but currently only the Entity Translation module does so (AFAIK).

Confusing :/

Correct

dharmalab's picture

Indeed, I'm trying to filter content by the language selected by the user via the language switcher. There doesn't seem to be an option for that in the filter criteria form. I.e. "Current user's language" doesn't seem to match the language selected via the switcher.

I've posted my question on this topic here:

http://drupal.org/node/1701854

Any suggestions welcome! :-)

Does this also work with views caching?

chweb's picture

I get wrong results with cache + Current user's language.

Views query caching, result

nonsie's picture

Views query caching, result caching or block caching? I am guessing you would get incorrect results with the first two since the query relies on a variable that changes from page to page.

I only have a "Node

bkosborne's picture

I only have a "Node translation: Language" option and it's not working. I have no caching on the view at all.... When I switch my site from spanish to english - the view still displays content from both languages. I have it set as an argument...

there is a filter "Content

rogerpfaff's picture

there is a filter "Content Negotation" you can use but it has a bug at the moment and you have to patch the module.

http://drupal.org/node/650552


Remember: I compute you!

You may also want to take a

LarsKramer's picture

You may also want to take a look at http://drupal.org/project/select_translation

Select translation implements a Views filter which allows you to select, for a group of nodes representing a same translation, which of the translation should be displayed.

awilliams's picture

in your Drupal 7 filter, add Content translation: Language and the check Current user's language box option.

Thanks but where?

sfsilks63's picture

I am sorry, but I cannot see this, maybe I do not have the correct module I am on version 7 at the moment. I just cannot seem to see the box for current users language box!

The funny thing I had it once, but after a reinstall no idea what I used.

Sorry for being an idiot. The site is www.atletasgranada.com and functions well but this email reply is the only part missing, would prefer not to have to translate myself

Regards
Stephen

Open the views in question

awilliams's picture

Open the views in question and do the following under "Filter criteria":

Click on "add" to add new filter criteria then a "Add filter criteria" colorbox will prompt up with all the available criteria
type in "Content translation: Language" in your "Search" text-field.
check the box with "Content translation: Language The language the content is in." and then click on "Add and configure criteria" to add the criteria.
You will be prompt with a "Configure filter criterion: Content translation: Language" colorbox with all the language filter options
Under "language" section with check boxes options, check "Current user's language" box.
click on "Apply" to apply the settings.

Then you are done. I hope you find helpful.
A Williams

How to ask for a specific field to be in the users language

matsbla's picture

Hi!

I try to make a multilingual slideshow. I have two fields: an image field that is not translatable (as it is the same picture for all languages) and a text field that is the caption of the field. Now I only want to show the images if there is a text to it in the visitors language (The current language of the website).

I tried to put on the filter "Current user's language" but it shows all the pictures anyway, and for those without caption, it just simply leave the caption out.

Mats

Enable - Follow the user's language preference

ad0nai's picture

In my case enabled "User: Follow the user's language preference"

1) Menu: Configuration » Regional and language » Languages (url: /admin/config/regional/language/configure)

Check the option: "User: Follow the user's language preference."

2) In views: add new "FILTER CRITERIA"- Content: Language (= Current user's language)

But how to manage missing translations

29axe's picture

I'm dealing with the exact same situation than ctmun.
Setting current user's language filter does work but for a list with contents not necesseraly available in all languages, we want to be able to show some content in the default language.
For ex. if I display a list of nodes in french (user's language) but that some nodes are not available in the user's language, I still want to show these nodes in another language that is available (in English).

Do you have a solution for this?

Enable - Follow the user's language preference

5418ryadav's picture

Great! It is working.

I have tried the Filter

ctmun's picture

I have tried the Filter Criteria to be equal to the Current user's language and this does work. Problem is not all content on the site is (or will be) translated. So I want to show the current user's language if available but English for ones that are not available. Any ideas?

mallikarjunvh's picture

i'm trying to change the language with language switch module,
language switch is working fine but content within the views block r not changing...plz help me out..thanks in advance

@ctmun and 29axe: I did what

Alpinist1974's picture

@ctmun and 29axe:

I did what I think you're trying to do in Drupal 6. It involved using the Views Or module, which is now built in to Views 3. My example is pretty complicated, but I think Node Translation: in Drupal 6 is much the same as Content Translation: in Drupal 7. Email me directly if you want a screenshot and the exported view.

Essentially though, you create two filters: one to limit the result set to the user's current language and another to filter the result set to to the default language. When adding the second filter, make sure to use the OR operator and create a filter group with the two filters. To filter out the overlapping results -- you only want to display content in the default language IF IT HAS NOT been translated -- I used Node Translation: Source and Node Translation: Child and Node Translation: Translation set node ID and created a Node Translation: Translations relationship.

Hopefully this is somewhat simpler to do in Drupal 7 -- I haven't tried yet -- and my use case is probably a lot more complicated than most. I think if you stack filters using the OR operator, you will be able to achieve your result.

@m_arjun

Did you try the other comments in this thread? They tell you how to do what you're trying to do, particularly:

http://groups.drupal.org/node/47478#comment-630833

I'm using Drupal 7 not 6

29axe's picture

I'm using Drupal 7 not 6

Thanks!

ctmun's picture

Thanks Alpinist1974! The same thing can definitely be done in Drupal 7 with the filters. I will try it out on my dev site as soon as my translators are done.

Thanks for reply Alpinist1974

mallikarjunvh's picture

I'm trying it in drupal7 only. but not used two filters..now i will try this one thanks..

not able to add both options

mallikarjunvh's picture

Plz send me the screen shots, my mail id arjun.v.h18@gmail.com

Did you try this?

Alpinist1974's picture

m_arjun,

Did you try this?

http://groups.drupal.org/node/47478#comment-630833

Read the earlier postings on this page also, they discuss how to use views with the language switcher.

My advice to ctmun and 29axe is for a different use-case and does not apply to you.

If all you want to do is make the view correspond to the language switcher, add a filter for Content: Translation: User's Current Language.

How to set if content is not translated

ctmun's picture

@Alpinist1974. Can you send your exported view? I can only get one language or all of them to show up in the views. I have one filter for the current user's language and another one to show if Node Translation: Source. I think I'm missing how to do the if the content has not been translated part. any help please?!

ctmunson@hotmail.com

Also, I have about 8 languages and some nodes are translated into 2 languages but not the other 6. So Node Translation returns that it has been translated, but that doesn't mean it was translated into the current user's language.

Right now I'm at the point where the views need to be all English or every single article node needs to be translated to every language before we can publish them. It's quite tricky. Adding the filters works for some languages but then doesn't for others.

ghalenir's picture

I also have D7 multilingual site and have same problem in views.

Here is the detail problem.
https://drupal.org/node/2020077

awilliams can you tell me what's wrong in my system ? can you list the modules that has to be enabled to get that option in the views ?

try to add node translation :

mysteryouss's picture

try to add node translation : child traduction or something like this in the filter.

Following module worked for

Shashwat Purav's picture

Following module worked for me:

Internationalization Views

How do you configure Internationalization Views

kcsimcity1's picture

Hi Shashwat Purav,

Basically i have everything setup for translation and installed Internationalization Views module.

I have 2 languages in the site. Contents without view is working fine with language switcher, when i change language content will change accordingly.

However if my page is generated using View module then translation does not work.
May i know exactly what setting have you done in the Internationalization Views?

For view to display translated contents:
What do i need to set at Relationship, Contextual Filter, Filter and Content.
Do i need to have different Body field for different language? Which is the right Body field for multi-language content?

Please advise and share. Many thanks in advance.

Regards,
SIM

@kcsimcity1 You need to add a

frederickjh's picture

@kcsimcity1

You need to add a filter. In views: add new "FILTER CRITERIA"- Content: Language (= Current user's language)

You may also need to enabled "User: Follow the user's language preference"

Menu: Configuration » Regional and language » Languages (url: /admin/config/regional/language/configure)

Check the option: "User: Follow the user's language preference."

Thank you @frederickjh -

kevster's picture

Thank you @frederickjh - thats what got it working for me!

Internationalization

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: