Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi all,
involved modules:
- Views 7.x-3.5
- i18n 7.x-1.7
- entity translation 7.x-1.0-beta2
Step to reproduce:
- Create a content type, enable "Multilingual support" using "Enabled, with field translation" option.
- Make only the body field translatable for this content type
- Create some nodes for this content type:
- Node A: choose "English" as source language
- Node B: choose "English" as source language
- Node C: choose "Italian" (or any other language you have) as source language
- Node D: choose "language neutral" - Translate the body field only for Node A and Node C
- Create a View that lists those nodes:
- Add field "content: title" and check "Link this field to the original piece of content"
- Add field "content: path"
- Make sure that field language is setted to "Current user's language" in advanced settings
- Notice that I don't want filter results per language, all nodes have to be listed, regardless of language
Views results:
Viewing the site in ENGLISH, the view shows:
- Record 1: (the node that as ENG as source lang, and body translated in ITA)
-Node A title linked to "mysite/en/node-A-alias"
-Node A path: "mysite/en/node-A-alias" - Record 2: (the node that as ENG as source lang, and NOT translated in ITA)
-Node B title linked to "mysite/en/node-B-alias"
-Node B path: "mysite/en/node-B-alias" - Record 3: (the node that as ITA as source lang, and body translated in ENG)
-Node C title linked to "mysite/it/node-C-alias" -> Error: should be "mysite/en/node-C-alias"
-Node C path: "mysite/en/node-C-alias" - Record 4: (the node that as LANGUAGE NEUTRAL as source lang)
-Node D title linked to "mysite/en/node-D-alias"
-Node D path: "mysite/en/node-D-alias"
Viewing the site in ITALIAN, the view shows:
- Record 1: (the node that as ENG as source lang, and body translated in ITA)
-Node A title linked to "mysite/en/node-A-alias" -> Error: should be "mysite/it/node-A-alias"
-Node A path: "mysite/it/node-A-alias" - Record 2: (the node that as ENG as source lang, and NOT translated in ITA)
-Node B title linked to "mysite/en/node-B-alias" -> Error: should be "mysite/it/node/[nid]"
-Node B path: "mysite/it/node/[nid]" - Record 3: (the node that as ITA as source lang, and body translated in ENG)
-Node C title linked to "mysite/it/node-C-alias"
-Node C path: "mysite/it/node-C-alias" - Record 4: (the node that as LANGUAGE NEUTRAL as source lang)
-Node D title linked to "mysite/it/node-D-alias"
-Node D path: "mysite/it/node-D-alias"
Results analysis:
- As you can see, "content:path" field is the only result always correct between languages
- Instead "content:title" link seems to point always to the SOURCE LANG path, regardless of the current language.
Actual workaround:
Uncheck the "Link this field to the original piece of content" option for title field, and do a rewrite of this field as a link, choosing [path] token as href.
Is this a bug or I'm missing something?
Thank you very much
Comment | File | Size | Author |
---|---|---|---|
#7 | views-node-title-link-does-not-respect-current-language-1849796-7.patch | 1.69 KB | pingwin4eg |
Comments
Comment #1
MXTNo response on this yet? I think this is a issue that can't be underestimate...
Comment #2
dawehnerFeel free to hang out in the issue queue and answer all the questions.
In general i'm really not sure whether your behavior is the expected one, or how views could do something here.
Field translation is a contrib module, so views will not automatically integrate with that one.
What views does is to check out the language of the content, which sort of refers to the language defined by the translation module, not entity_translation. Maybe we would have to figure out how url() fixes this particular problem but in general it seems to be a doable question.
Comment #3
MXTThank you very much for your answer dawehner,
At the moment yes, but both Views and Entity Tranlastion will be in Drupal 8 core, so I think is already time to put the right attention since now to the issue.
Then, it can be considered an inconsistency the fact that "content: path" field gives a different result from "content: title (linked)" in the same record?
Comment #4
liquidcms CreditAttribution: liquidcms commentedi am not sure if this is related; but similar much more basic issue:
- for a node type which is NOT enabled for multilingual support.
- add a "content: title" field in views
- select "Link this field to the original piece of content"
the url for this becomes /en/[title]
when the site is switched to FR, the url remains as /en/[title] when it should be /fr/[title]
i had expected Views did the "right thing" here so have this all over a site of ours. my solution has been to go through all views and add nid field and rewrite this as [title] output as a link and set link path to node/[nid]; this then does the right thing.
pretty sure this would need to be considered a bug and i will likely look in to fixing it as it will be quicker than changing all the views i have on this site. if this is no way related to this issue; let me know and i will open a new issue.
Comment #5
liquidcms CreditAttribution: liquidcms commentedlooking at the render_link function in views_handler_field_node.inc the language is pulled from this line:
but this pulls the node_language; which is the language the node is defined in, which for node types which are not being translated; this is the Drupal base language (EN). this isn't correct. we should be pulling the site language here.
as a quick test i forced $language = 'fr' here and this mostly works. my url is now /fr/node/[nid] which does take me to the correct page (my language neutral node; but with the site in FR). but what i was hoping for was a url of /fr/[title]. this seems as though it would be a bug in the Global Redirect module as it should not allow me to go to node/[nid] if there is an path alias (and if i enter the url as /en/node/[nid] sure enough global redirect does the right thing and switches me to /en/[title])
so i am sure there is a bug in the Views handler here but i would bet not as simple as setting language to the site language. there likely needs to be a check if the node is actually language neutral and then set it to site language.
also, more as a question, a view has a setting for "Field Language" with options including "current user's lang" as well as "Language neutral". neither of these help this situation.
Comment #5.0
liquidcms CreditAttribution: liquidcms commentedRemoved some
for increase legibility
Comment #6
pingwin4egI don't think there should be any check if the node is actually language neutral or not. All this check is already a job of translation modules. As we can see in views_handler_field_node_link.inc (field "Content: Link" which as "Content: Path" works nicely) there is no code about language. So removing it from views_handler_field_node.inc would be convenient solution in my opinion.
Comment #7
pingwin4egTry this quick fix.
Comment #8
nbuonin CreditAttribution: nbuonin as a volunteer commentedThere's a module for this. Try using Internationalization Views
First enable module. Then, when building your view, use the field called "Entity Translation: Title", rather than "Content: Title".
Comment #9
Graham Leach CreditAttribution: Graham Leach commented(cross-posted because I am not sure where this issue lies, forgive me if this breaks a policy somewhere)
https://www.drupal.org/node/866170#comment-10352693
Hmmm,
The Link this field to its node feature does NOT work with a Multi-Lingual Drupal 6, Ubercart 2 implementation.
The URL for the targets that feature the Link this field to its node work correctly where they are available, i.e.:
With these, I get what I want and translation works properly:
English:
http://holisticpethelp.com/products/nose-it-k-9-ball-flex-red
Chinese:
http://holisticpethelp.com/zh/products/nose-it-k-9-ball-flex-red
But where this option is NOT available and when trying to link the BODY of the content associated with this product manually, things break down:
A) Include Node: Path, Exclude from Display checked
B) Include Node: Link, Exclude from Display checked (just for safety)
C) Customize Node: Body to reference [path] when Output this field as a link is checked
Will give you the following URL linked to the Node: Body text:
http://holisticpethelp.com/zh/zh/products/nose-it-k-9-ball-flex-red
A) Where in the core code for VIEWS is this happening?
B) Can anyone suggest a fix?
UPDATE! HERE'S A WORKAROUND:
Add Node ID to selected fields
1) Add Node: Nid to selected fields
2) Re-position Node: Nid to top of fields
Configure and link desired display information (in my case Node: Body)
3) Check "Output this field as a link"
4) In Link path:, enter node/[nid]
Comment #10
TokiThanks Graham, your workaround works perfectly. The issue is still present (Views 7.x-3.13). With node/[nid] as a new output, Views transforms the path with the correct language prefix and the pathauto pattern, for example.
Comment #11
knalstaaf CreditAttribution: knalstaaf commented#7 seems to do the job.