Greetings,
As I found out that there is possible bug or conflict in language selection of taxonomies on nodes.
Summary of the problem:
Taxonomies are shown as depend on orginal langauge of node (if it don't have translated version of the node) when it should be another langauge.
Steps
-Create a taxonomy vocabulary with 3 languages with allowed translation.
English | French | Turkish
Hello | Bonjour | Merhaba
House | Maison | Ev
-Create a node type with allowed to translation (Name of the content type: "testing", field name "taxonomy").
-You may translate field's name or other details. (french version "taxonomie", turkish version "taxonomi" ). We choose interface language to display.
-Add a field with term references
-Create a new content, name it "a new content" in Turkish. Lets choose "Merhaba" in "taxonomy" field. Its node number is "5".
-Open this new node example.com/tr/node/5 (default langauge of site is English )
You may see as
taxonomi: Merhaba
-Now use URL as example.com/fr/node/5
you should see
taxonomie: Bonjour
However it appears as
taxonomie: Merhaba
in example.com/node/5, English langauge
taxonomy: Merhaba
If you create translated version of "a new content" as French, example.com/fr/node/5 url will show you as correct one.
taxonomie: Bonjour
But still English would be (example.com/node/5)
taxonomy: Merhaba
The need of the problem is even if user didn't translate the content, taxonomies should appear in correct form, like its field names.
Note: I am not really sure it is a dublicate problem but as I searched in last 2 days, I only found very old examples of problem (exp:
https://www.drupal.org/forum/support/post-installation/2010-03-26/taxono...) and another maybe more up-to-date similar one. (https://www.drupal.org/project/drupal/issues/2930458)
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | taxonomy-term-translation-on-not-translated-nodes-3071330-18.patch | 1.43 KB | pablo_pukha |
| #17 | Screenshot 2024-06-23 at 11.36.24.jpg | 19.21 KB | monkk |
Issue fork drupal-3071330
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Erso commentedComment #3
avpadernoComment #9
larowlanIs each node referring to the same tid?
Comment #11
marksmith commentedI can confirm that this is indeed an existing problem in views.
Let's presuppose that the Taxonomy vocabulary is localized, in two languages.
If node content is either (1) not translatable or (2) translatable but not localized (language not specified), taxonomies show up in the localized version, in the language chosen for the interface (e.g. via url). That is the expected behavior.
If node content is both (1) translatable and (2) localized (i.e. content with a specified language), taxonomies will always show up in the language chosen for the localized content (irrespective of the interface language). That is problematic if you do not have a translated version of the node content in the desired language but you do have a translated taxonomy in the desired language.
It would be much more useful when taxonomy language would follow the interface in such situations (like field names, as suggested by the reporter).
Comment #14
smustgrave commentedBased on #11 this could still be an issue. Moving to active and tagging for IS and steps to reproduce
Comment #15
monkk commentedI can confirm that D10 as well:
1. I have nodes that are translatable, but not localized
2. I manage language via session
3. Opening node in non-localized language all labels are translated, but taxonomy field itself is not.
Comment #16
avpadernoComment #17
monkk commentedI attached image to describe issue better:
1. Node is not translatable, but not localized, ie only id default language
2. Reviewing node by forcing language in URL or managing it via session results in same: label translated to target language, but fields with taxonomy reference displayed in default language, but not URL/Session language.
Would be happy to pay for the fix if anyone would be intersted.
Comment #18
pablo_pukha commentedI have reviewed the issue and worked on a patch.
The patch fixes this by check if formatter is entity reference. While this solution works for the reported issue, I am unsure if it covers all edge cases. Feedback on this would be greatly appreciated.
Please review the patch and let me know if there are any improvements or alternative approaches you’d suggest
Comment #19
thomas.wardin commentedDoes exactly what I needed on a D11 site. Did not find any unintended side effects so far.
Thank you, pablo_pukha!
Comment #21
pablo_pukha commentedPushed an MR with a better approach.
Instead of branching on the formatter type in EntityViewDisplay (which is a layering violation), the fix is in EntityReferenceFormatterBase::getEntitiesToView(): we no longer pass the referring entity's $langcode to EntityRepository::getTranslationFromContext(). Omitting it makes the method fall back to the current content language, which is what we actually want when resolving translations of referenced entities.
Added a test case in EntityReferenceFieldTranslatedReferenceViewTest for a translatable referrer without a translation in the target language.
Comment #22
pablo_pukha commentedComment #23
smustgrave commentedNot seeing the MR, but still needs a summary update though please.