With the normal translation there is a filter that checks the languages of the node. So you could for example only display the nodes that are in the users language.
With Entity translation this filter doesn't work because the node is in 1 language en the field are translated. The problem now is that if a node is published but no translation is provide a message will be displayed that the node is not translated or it will show the node but only the fields that can't be translated.
By turning on 'Enable language fallback' the node will be displayed in another language but this is an overall setting and maybe you just want this for certain node types or views.
So a filter that can be set per view would be more flexible. Maybe something that checks if a translation for the node is added?
Comment | File | Size | Author |
---|---|---|---|
#47 | entity_translation-filter_views-1330332-47.patch | 577 bytes | clairedesbois@gmail.com |
| |||
#18 | entity_translation.patch | 1.45 KB | Jax |
#6 | views-filter.patch | 1.46 KB | Jax |
Comments
Comment #1
GiorgosKpossibly related: #1305770: Entity Translation shows all translation if using a contextual filter and #1346242: Duplicates in views using entity translation when sorting results
Comment #2
GiorgosKhere is my use case which needs a field
content type entity translated
with title_field and image field both entity translatable
view using content:fields
if my view gets nodes which all have translations the view works great using no filter and settings "Query settings:Settings Distinct" and "Field Language:Current user's language" and on the field settings I check "hide empty fields"
when one or more nodes don't have translation the view gets messud up if I add a field which is never empty for all language like NID, Edit Link etc
using a filter like "title_field NOT EMPTY" or "image field NOT EMPTY" does not work either and views shows all nodes, some nodes might have only NID or Edit link displayed since there is no real translation of the tile or image ...
thus a views field language filter would be most useful in such cases
a temporary workaround would be to user hook_views_query_alter(&$view, &$query) OR hook_views_pre_render(&$view) or user Views PHP for filtering the output
Comment #3
danielnolde CreditAttribution: danielnolde commentedfyi: Filter views by ET translation language
I'm planning to implement (and contribute via patch) a views filter that filters the selection of entities in views for selecting only entities that have a original version or translation in the current display language.
Please give your input at http://drupal.org/node/1402692
Comment #4
danielnolde CreditAttribution: danielnolde commentedA sandbox module for filtering content queries for Entity Translation content by proper language has been created, see http://drupal.org/node/1402692#comment-5468944
Comment #5
Kristen PolComment #6
Jax CreditAttribution: Jax commentedI was rather thinking about something like what I've attached. This filters on the language field of the entity_translation table. So as long as you haven't created a translation it doesn't exist in this table and you can filter on it.
Currently the patch only works with the node table but see for example field.views.inc to make it more generic to work with all entities. Will continue to work on this.
Comment #7
danielnolde CreditAttribution: danielnolde commentedThat's cool, too, Jax. I think _both_ your filter in #5, using views' filter alteration, and my filter in #4, using query rewrite (configurably broadened to any query in Drupal) should be included into ET. And both filters need some work to cover non-node entities, too. Perhaps we can join forces, and perhaps the ET maintainer can provide some opinion on this and how/in what form to get it into ET (blink-blink towards Daniel ;)
Comment #8
plachHi Daniel, I'm definitely in favor of having built-in Views support, unfortunately I could not follow your progress yet. Would you mind to summarize the current status in the other issue, if anything changed from http://drupal.org/node/1402692#comment-5468944?
Obviously we need to support any entity.
Comment #9
BarisW CreditAttribution: BarisW commentedJax, any updates on this? Would love to be able to create a view that shows me all files (images) that are untranslated. Thanks!
Comment #10
Jax CreditAttribution: Jax commented@BarisW The patch provided in #6 works so I'm not sure what you want.
Comment #11
BarisW CreditAttribution: BarisW commented@Jax:
I need it to filter images (files), not nodes. That's why I was wondering if you got any further (as you mentioned you were continue working on it)?
Comment #12
Jax CreditAttribution: Jax commentedOh, I guess I did say that. I'll try to do that then in the next couple of days.
Comment #13
BarisW CreditAttribution: BarisW commentedCool, thanks!
Comment #14
khaled.zaidan CreditAttribution: khaled.zaidan commentedGreat, this seems to work... would love to see it committed!
Comment #15
plachI think this particular use case should be solved by Views, since it's basically fully supporting the core Field language API. What @danielnolde linked in #3 is a different issue that belongs to ET.
See #1515156: Expose the field language column for translatable fields.
Comment #16
plachMarked the following as duplicates of this one:
#1305770: Entity Translation shows all translation if using a contextual filter
#1346242: Duplicates in views using entity translation when sorting results
Comment #17
plachActually postponing to see if the patch linked above is accepted in Views.
Comment #18
Jax CreditAttribution: Jax commentedI've updated the patch to support all the entity types since I said I would do that. Is completely untested.
Comment #19
stevieb CreditAttribution: stevieb commentedI tried to using the patch to show a glossary of node types with a thumbnail, title and subtitle in both a grid & table
.. using all choices in "Entity translation: Language" (users language, german or english) ... sadly it failed and everything is still doubled
see img
Comment #20
plachComment #21
cossimo CreditAttribution: cossimo commentedJust to follow up on what stevieb wrote in #19, my experience was the same. The patch does expose the entity_translation table as Views filters; however, this doesn't help with filtering out duplicates that result when the fields of a node are translated. From my experience, when a node has X translatable fields, and the node has been translated into Y languages, XY duplicate results will appear for that node. (This is the case regardless of whether Language Fallback is enabled or not.) Setting the "Query settings" to "Distinct" will prune the results down some; however, at best, I get a duplicate result for every translated field in the node.
This particular issue is different from the original issue in this thread, which focuses more on gracefully handling untranslated nodes and fields, and as such should probably be submitted as its own issue. However, it seems so fundamental, that I would just like to make sure I'm not missing something before I submit it as its own issue.
That is, is there a tool, filter, or strategy I'm missing that will allow me to filter a result set in such a way that multiple translated fields associated with a single node do not result in duplicate results for that node? And if there is no way to filter results in this manner, where should this issue be submitted? Under the Views project or the Entity Translation project?
I have attached an export of the view. The version of Entity Translation I am using is 7.x-1.0-alpha2 (6-16-12), and the version of Views I am using is 7.x-3.3+173-dev (6-17-12).
Thanks very much for your consideration and help with this!
Chris
Comment #22
torpy CreditAttribution: torpy commentedYea, I had that same problem. The following piece of code may not be the best way to do things but seems to solve it for me. This would go in a hook_views_query_alter() function. It's hardcoded to only work for views that display one type of node but can be modified to work for multiple node types.
The issue seems to be that views sometimes uses entity_load to get field definitions, but other times just JOINs the field table directly on and retrieves data that way.
Comment #23
creando sensaciones CreditAttribution: creando sensaciones commentedsubscribe
Comment #24
BarisW CreditAttribution: BarisW commented@creando sensaciones: Stop subscribing, start following
Comment #25
cossimo CreditAttribution: cossimo commented@torpy, re: #22, from what I've seen so far, this works great! Thanks so much!
C.
Comment #26
Yuri CreditAttribution: Yuri commentedDo i undestand right that #22 is the best solution so far, for filtering views fields by entity language?
If so, then I don't know how to implement the code provided in #22, sorry.
A patch or steps to get this working would be great, thanks!
Comment #27
heretic381 CreditAttribution: heretic381 commentedSame here. I've tried with template.php, but cant get this to work.
Comment #28
cossimo CreditAttribution: cossimo commentedYou will need to put the function in a custom module. I can post mine for you tomorrow for reference.
C.
Comment #29
heretic381 CreditAttribution: heretic381 commentedOk. That would be helpfull I think.
Comment #30
cossimo CreditAttribution: cossimo commentedVery sorry... This slipped my mind. Attached is my custom module. (It may not meet Drupal coding standards, but it works.)
C.
Comment #31
Yuri CreditAttribution: Yuri commentedJust to be clear about the main topic of this issue: Entity translation: Views field language filter.
I use entity translation on groups (which seems the only way for OG to translate groups)
My issue is that I want to filter groups in views, by current user language.
When I select Content: Language (in Current user's language) the view doesnt show any results, doesn't show the groups that are translated.
As for the module mentioned in #30, I installed it but have no idea what i should see or do, i don't see any change in settings or views output.
Can someone please assist me with this issue, it seems that this thread is the only one that handles views language filter for entity translations.
Comment #32
cossimo CreditAttribution: cossimo commentedYuri:
Per recent activity addressing this problem in Views, the following patch is a better route to take for resolving this issue: https://drupal.org/node/1515156#comment-6511750
After applying the patch, the language(s) for any translatable field can be used as filter criteria for the view. It works very well, though in some instances, I've also had to check "Distinct" under Query settings.
C.
Comment #33
plachYes, that patch over there has been committed to the Views project so we don''t need this anymore.
Comment #34
calculus CreditAttribution: calculus commentedIs there a patch/fix for #21 problem, other than #22 manual override?
Comment #35
plachThe fix is in the Views issue linked above: you can specify a filter for a particular language as you would do for the field delta.
Comment #36
calculus CreditAttribution: calculus commentedThank you.
Comment #37
Trias2013 CreditAttribution: Trias2013 commentedWhat worked for me:
Greetings
Comment #38
justintorrent CreditAttribution: justintorrent commentednot work for me!
Comment #39
bdecarne CreditAttribution: bdecarne commentedThanx, #37 worked like a charm.
Comment #40
jrochate CreditAttribution: jrochate commentedI didn't even need the Advanced Relationship.
Just add the filter criteria on entity translatable item, and voila.
Thanks for the heads-up
Comment #41
schifazl CreditAttribution: schifazl commented#37 worked for me too. thanks!
Comment #42
SunnyGambino CreditAttribution: SunnyGambino commentedThanx, #37 worked like a charm. Cool solution! :)
Comment #43
jetwodru CreditAttribution: jetwodru commentedwhy #37 does NOT work for me ? I only have a translatable item (position) under Sort Criteria and all are screwed up. Following #37 sitll does not work, any other solutions ? Without this being solved, Entity Translation has become useless to me but I really love its working concept. Thanks
Comment #44
plachYou should find a "position:language" item in the filters section: add it, select the type of language filtering and you should be done.
Comment #45
jetwodru CreditAttribution: jetwodru commented#44, thanks, it works now even without adding any Relationship but the Language Fall Back for the Views do NOT work. I have 5 languages enabled but not all contents are translated for each language and English being the default language all the times. I wanted those contents with no translations will always fall back to English instead of showing empty block.
P/S: I'm quite confused. It seems various ways of working around with Views. Some people can get it to work with only Entity Translation:Language and some require adding Relationship. However, I have to select the Translatable Field Language in order to work. I can't really come to a conclusion of how Entity Translation works with Views in different contexts. I wish I would be enlightened on its usage. Thanks.
Comment #46
danielbehina CreditAttribution: danielbehina commentedI tried all and nothing works unless I have found simple soulution here:
ET is the best and I can't live without it, thank you for your work! Hope it helps.
Comment #47
clairedesbois@gmail.comI have make a patch for the last version of dev. Just add filters on entity translation informations.
Comment #48
liquidcms CreditAttribution: liquidcms commentedjust to muddy the waters even more... i am trying to filter by contextual filter. this issue seems to refer to only filters (and i have tried adding relationship and contextual filter for language and this does not work).
but i see plach also closed this issue: #1305770: Entity Translation shows all translation if using a contextual filter (which is about contextual filters) stating it was a duplicate of this issue.
so, does this also work for contextual filters? any hints as to setup?
just to be clear that i have same issue:
- i have a json output from a view which is set to "Field language: Current user's language" (not sure how this doesn't interfere with any filter settings??).
- the path to my page is json/data
- if i go to en/json/data i get english data
- if i go to da/json/data i get danish data
YAY.. perfect!!
but now, i have a cron task which calls views_embed_view() to pull data in each language (to calculate a hash on the data).. and i need to pass an arg for language to views_embed_view() to get the correct data.
sorry to re-open but this is closed as duplicate; when others are closed as duplicate stating this is the original (and nothing listed here saying what this is the duplicate of).. getting very confusing..
Comment #49
liquidcms CreditAttribution: liquidcms commentedthought i would be smart and simply set global language within my cron language loop.. but oddly that has no impact (always returns EN data).
Comment #50
feldmarv CreditAttribution: feldmarv commentedGREAT THANKS to, #37! This works great, after searching for hours.
Comment #51
Renrhaf#37 works great, thank you.
Comment #52
kenorb CreditAttribution: kenorb commentedComment #55
samit.310@gmail.com CreditAttribution: samit.310@gmail.com commentedHi All,
Following Code works For me.
Comment #56
parameshrag CreditAttribution: parameshrag commented#37 works great, it saved my time, thank you.
Comment #57
knalstaaf CreditAttribution: knalstaaf commented#37 may work for the overall approach, but it may be insufficient for views using a contextual filter (such as NID), as mentionned in #48. For the latter a solution my be provided in #1346242-21: Duplicates in views using entity translation when sorting results (regardless of whether sorting criteria are being used or not).
It may also be fixed by simply adding the very same field as a filter, but as the language property of it (e.g.:
field_images:language
)Comment #58
ezoulou CreditAttribution: ezoulou commented+1 for clean workarround #37 :-)
Comment #59
GoZ CreditAttribution: GoZ at Centarro commented#37 does not work for me. I can't find filter.
Otherwise, #47 works great. It's add every filters i need and query looks great
Comment #60
4kant CreditAttribution: 4kant commentedThanks to #46 - no patch necessary ;-)
Comment #61
cosolom CreditAttribution: cosolom commented#46 work's fine. thanks
Comment #62
plachPlease don't reopen closed issues, #47 is about making all ET info available to Views as fields, filters and sorts and therefore is a new feature request. Additionally it works only for nodes so it cannot be committed in the present form. Feel free to open a new issue and link it here because this has become totally unmanageable.
Comment #63
alsator CreditAttribution: alsator commentedThis works for me: