Problem/Motivation
Some Sites require switching of content languages whilst site interface is another - i.e. approvers for multilingual content.
When using Content language detection, menu blocks follows content language negotiation. For most/some projects - menus are part of the site interface and therefore we should have an easier way to choose whether to follow site interface or content negotiation.
How to Reproduce
1. Add Languages (zh-hant)
2. Interface text language detection - Choose URL
3. Check - Customize Content language detection to differ from Interface text language detection settings
4. Content language detection - Selected language (zh-hant)
5. In both En and zh-hant sites - all menu blocks will be zh-hant
Possible Clauses
Proposed resolution
A suggestion would be , which Content Language Detection is enabled. Allow choosing whether language negotiation is based on Site Interface OR Content for that Menu .. Default is Content?
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #43 | language-detection-3101747-43.patch | 5.07 KB | pierreemmanuel |
Issue fork drupal-3101747
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
xenyo commentedComment #3
kt2ssh commentedComment #4
kt2ssh commentedComment #5
ravi.shankar commentedComment #6
kt2ssh commentedHi , here is the new patch, it is now configurable from "Content Entity Negotiation" :
1. install new drupal 8.9-dev
2. enable language & content translation module
3. /admin/config/regional/language , add a new language (Chinese, Traditional)
4. /admin/config/regional/language/detection , enable "Content language detection", enable "Content language" and drag it to the top
5. /admin/structure/types/manage/article , check "Enable translation"
6. /node/add/article , add a new article with translation (both en and zh-hant)
7. /admin/structure/menu/manage/main , add a new menu "home" with link "< front >", then translate the menu as "首頁"
8. /admin/config/regional/content-language, enable "Custom menu link" and check all fields under this section
9. /zh-hant/node/1?language_content_entity=en visit the article just created (using zh-hant url prefix), you will see that both article content and the newly created "home" menu are showing in zh-hant language, however menu should follow the user interface language instead of the content.
10. apply the patch "3101747-7.patch"
11. /admin/config/regional/language/detection/content-entity, here is a new option "Force menu follow Interface Language" , check this option and save.
12. flush all caches
13. /zh-hant/node/1?language_content_entity=en , now the content is showing english version and the menu is showing as zh-hant language
Comment #7
kt2ssh commentedComment #8
sutharsan commented@xenyo, Did you intentionally assign the issue to yourself? Did you forget to turn it off? See https://www.drupal.org/node/2172049 about how to use the 'Assigned' to field of an issue.
I'm un-assigning you, assuming it was not intentionally and you have not been active in this queue for two almost weeks. Feel free to re-assign if my assumption was wrong.
Comment #9
xenyo commentedYeah thx @Sutharsan. kt2ssh is in our same company and I was helping him open an issue .
We are not that familier with contributing so thx for the help. For this issue, do we just wait for review or is there anything else we can help.
Comment #10
xenyo commentedComment #14
madhu_h commentedVerified and tested the Merge request !
https://www.drupal.org/files/issues/2019-12-27/3101747-7.patch
Testing Steps:
. install new drupal 8.9-dev
2. enable language & content translation module
3. /admin/config/regional/language , add a new language (Chinese, Traditional)
4. /admin/config/regional/language/detection , enable "Content language detection", enable "Content language" and drag it to the top
5. /admin/structure/types/manage/article , check "Enable translation"
6. /node/add/article , add a new article with translation (both en and zh-hant)
7. /admin/structure/menu/manage/main , add a new menu "home" with link "< front >", then translate the menu as "首頁"
8. /admin/config/regional/content-language, enable "Custom menu link" and check all fields under this section
9. /zh-hant/node/1?language_content_entity=en visit the article just created (using zh-hant url prefix), you will see that both article content and the newly created "home" menu are showing in zh-hant language, however menu should follow the user interface language instead of the content.
10. apply the patch "3101747-7.patch"
11. /admin/config/regional/language/detection/content-entity, here is a new option "Force menu follow Interface Language" , check this option and save.
12. flush all caches
13. /zh-hant/node/1?language_content_entity=en , now the content is showing english version and the menu is showing as zh-hant language
Test Results:
There is an error while applying patch
Refer SS
Test Status: FAIL
Comment #16
lobsterr commentedReroll the patch #3101747-7: When Content Language Detection is enabled, menus are forced to follow Content when Site Interface is the preferred choice sometimes.. Basically only description of the plugin was updated.
Comment #17
ranjith_kumar_k_u commentedComment #18
kristen polThanks for the updated patch. Tagging for manual testing and to add tests.
Comment #19
kristen polMoving back to needs work for tests.
Comment #20
nicolas s. commentedPatch works with an D9.3.9
Comment #21
lobsterr commentedI added tests
Comment #23
lobsterr commentedThe tests fail, but it is not related to the current issue. I assume something is broken on the tests system
Comment #24
ambikahirode commented#21 working For me on local 9.4
Verified and tested the issue by applying patch 3101747-21.patch . Patch was successfully applied and issue got fixed.refer Screenshot
Comment #26
simohell commentedComment #27
sonnyktManual test results on Drupal 9.5.x-dev.
Testing steps
* Enable Language and Content Translation module
* Set default site language to English
* Regional & Language > Languages
/admin/config/regional/language: add "Chinese, Traditional" (zh-hant)* Regional & Language > Detection and selection
/admin/config/regional/language/detection: enable URL in "Interface text language detection", enable "Customize Content language detection...", enable "Content language" in "Detection method" and move it to the top.* Regional & Language > Content language and translation
/admin/config/regional/content-language: enable "Custom menu link" and check Menu link title, Description, and Changed.* Enable translation for content types.
* Add a node in English, and add a Chinese translation
* Add a menu link for the created node in English, and add a Chinese translation for the menu link.
On Drupal 9.5.x without any patch:
* UI language: En






/first-page- menu shows links in English, content shows English* UI language: En - Content language: En
/first-page?language_content_entity=en- menu shows English links, content shows English* UI language: En - Content language: Zh
/first-page?language_content_entity=zh-hant- menu shows English links, content shows Chinese* UI language: Zh
/zh-hant/first-page- menu shows links in Chinese, content shows Chinese* UI language: Zh - Content language: En
/zh-hant/first-page?language_content_entity=en- menu shows links in Chinese, content shows English* UI language: Zh - Content language: Zh
/zh-hant/first-page?language_content_entity=zh-hant- menu shows links in Chinese, content shows ChineseVanilla Drupal 9.5.x works quite consistent and I don't think it is an issue.
After applying patch #21:
* UI language: En




/first-page- menu shows links in English, content shows English* UI language: En - Content language: Zh
/first-page?language_content_entity=zh-hant- menu shows Chinese links, content shows Chinese* UI language: Zh
/zh-hant/first-page- menu shows links in Chinese, content shows Chinese* UI language: Zh - Content language: En
/zh-hant/first-page?language_content_entity=en- menu shows Chinese links, content shows ChineseWith patch #21, the results are not consistent. The menu shows Chinese links when UI:En and Content:Zh, but it does not show English links when UI:Zh and Content:En.
Comment #28
simohell commentedHi,
Thanks @sonnykt
We discussed this a while ago with the Drupal UX group. I was just about to ask for some screenshots and more detailed instruction as we were not able to reproduce this testing using an Umami demo installation.
I wonder if this is theme specific issue?
Comment #29
sonnyktHi @simohell,
I was testing the issue with the standard profile and theme Bartik.
Comment #30
kristen polThanks for testing and the feedback.
Moving back to needs work based on above. Maybe this needs the UX group to take another look?
Comment #31
kristen polTests were added so removing tag.
Comment #32
lobsterr commentedI will check the cases described in #27
Comment #33
lobsterr commentedAfter reproducing one to one the steps and results provided on the screenshots in #27 with 9.5.x.
I have different results. The patched version works as it should and not patched is not consistent.
I introduced steps, which are different for me.
Clean Drupal 9.5.x
1) /first-page?language_content_entity=zh-hant
Content: Chinese
Menu: Chinese
2) /zh-hant/first-page?language_content_entity=en
Content: English
Menu: English
Patched Drupal 9.5.x
1) /first-page?language_content_entity=zh-hant
Content: Chinese
Menu: English
2) zh-hant/first-page?language_content_entity=en
Content: English
Menu: Chinese
So, to sum up. For me the patch works as expected.
@sonnykt Could you please double check or someone else ?
On my side I did it several times.
Thank you in advance
Comment #36
lobsterr commentedReroll the patch for 10.2
Comment #37
smustgrave commented11.x is the current development branch.
It's recommended to use MRs as patches are being phased out and don't automatically run anymore. Will manually trigger but see that new functions should have a return typehint, didn't do a full review though.
Comment #39
lobsterr commentedThanks for info, I have created a MR
Comment #40
smustgrave commentedHiding patches for clarity.
Left some comments but also appears to have a test failure.
Comment #41
smustgrave commentedComment #43
pierreemmanuel commentedHi,
Here is the reroll of patch #36 for drupal 10.3.x.
Regards
Comment #44
erwangel commentedSorry for the long post that follows but I found this is the most mature issue resolution and I hope my test and comments may contribute to further clarify the problem and improve its solution.
It seems that menus are displayed in their original or interface language or content language according to their provenance (how where they generated). In some cases this can lead to mixture of translated and untranslated menus. But the problem is not only in menus, displaying of block titles, field labels can also create a language confusion.
I am of the opinion that switching content language should not affect the interface (menus, blocks titles and content, any links, etc.) and only change the main content (node or views listing), not event the entire page content (related blocks and other extra content), i.e. only change what is called the "Main page content" in block layout. This opinion because users may be able to read an article in various languages but have a preferred language for the user interface and the rest of the content. They just occasionally prefer read an article in a language different of their usual language. An American-spanish-speaken citizen may want its site in English but if an article is published in both English and Spanish he may prefer read the article in Spanish without seen the entire site switched in Spanish. I think that is the main reason for separating interface and content translation.
Now here my observations on a D10.4 installation before applying the patch.
Configuration: fr (french default), en (English), de (Deutsch - German)
Interface detection: from url (path prefix)
Content detection: content language (request parameter 'language_content_entity')
In order to avoid fastidious repetitions, I defined tree types of menus:
- TYPE 1: menu links provided by the Standard module (ex. "Home" link) or by Views or by Taxonomy Menu module (you can not edit nor translate them in "admin/structure/menu")
- TYPE 2: menu links provided by nodes ("Provide a menu link" option in node's edit page and you can also edit/translate in "admin/structure/menu") or empty links ( to display link text only)
- TYPE 3: any other menus manually created and translated in "admin/structure/menu" either with internal path or a node link they
Cases:
* Interface FR (default), no request param
- url: /page-fr-url (aliased on node's title) => content, content field labels, menus, blocks in FR as expected
* Interface FR (default), language_content_entity=FR
- url: /page-fr-url?language_content_entity=fr => same as above as expected
* Interface FR, language_content_entity=EN (or DE)
- url: /page-fr-url?language_content_entity=en
- Content is displayed in content language (EN), field labels too, block title and content are in interface language (FR)
- Menus TYPE 1 titles: respect the interface language (fr)
- Menus TYPE 2 titles: they follow the content language (en).
- Menus TYPE 3 titles: they follow the content language (en)
- All Menu urls are build according to the interface language (fr is default so no prefix in url)
- Local task tabs respect the Interface language (fr)
As Result: A confusing mixture of menus translated in one or other language!
* Interface language EN, no request param
- url: /en/page-en-url (aliased on node's title)
- Content shows in default FR (content lang) but field labels in EN! (interface lang), block titles in interface language EN
- Menus TYPE 1 respect the interface language (EN)
- Menus TYPE 2 and 3 are in... default FR! even when both the menu text the linked page have a translation in the current interface language
- All Menu urls are build according to the interface language (/en/___)
- Local tasks respect interface (EN)
--- Note 1: In untranslatable and in untranslated nodes, same behavior as above (mixed translations)
--- Note 2: In Views pages, all menu types are displayed as expected in the interface language
Conclusion: it is like the lack of language_content_entity parameter has a fallback to the default content language.There may be some logic here too but ths leads to unexpected result: having make no choice about content language one could expect that the entire page would be in the interface chosen language.
* Interface language EN, language_content_entity=FR (default)
- url: /en/page-en-url?language_content_entity=fr => Same as with no request parameter
* Interface language EN, language_content_entity=EN
- url: /en/page-en-url?language_content_entity=en => everything is in English
* Interface language EN, language_content_entity=DE (default FR language is not implied in interface nor in content)
- url: /en/page-de-url?language_content_entity=de
- Content displays in the content language (DE), block titles are in interface language EN even those placed inside content with layour builder (I think they should be consistent with the rest of node's content, i.e. have the content language DE)
- Menus TYPE 1 respect the interface language (EN)
- Menus TYPE 2 and 3 follow the content language (DE)
- All Menu urls are build according to the interface language (/en/___)
- Local tasks respect interface (EN)
Conclusion
There is no validation of language_content_entity's value at least from user's point of view. You can set manually whatever you want, numbers, letters, special characters, you never get an error message.
In views content (pages and blocks): In views you have different choices for the Rendering Language, but titles will display according to the interface language.
Content blocks:
Added on a page with block layout (/admin/structure/block): title in interface language, content in content language.
Added in a node with layout builder (/node/nid/layout): no way to translate the title, content in content language
In node's full mode: title and content they display in the content language but field labels and views blocks inserted with layout builder are in the interface language. If I a am able to understand the content in one language I am able to understand the fields labels and the block titles too no? Are Field labels and block titles part of the interface or do they belong to the content ? (I am for the second option)
Menus: titles obey to the interface language if links were generated by a module, but they obey to the content language if they were generated by a node or "by hand". In any case, the underlying url is build according to the interface language. So you can have a link whose text is in German but the url is the English one. Once you click it the interface will switch to English. Not necessarily what is desired.
What can we do ?
I know there have been long discussions about content and interface translation. Looking to the current situation and the several patches here and there that try to resolve one or an other problem, It doesn't seem like it clarified anything. I think we have to radically simplify and consider that
1) Only menus, action links and buttons are part of the interface and they should behave according to the interfae language regardless their provenance.
2) Block title and Field label's function is to announce what follows, i.e. content. So they should be considered as content and display according to the content language
3) Have the option to apply content translation only to what is called the "Main page content" in block layout or to the entire page
4) Menu link titles and underlying urls should be language complaints
4) Verify that language_content_entity value validates against the available language, otherwise throw an error