Token 8.x-1.6
Using Twig Tweak (8.x.2-4) I put the following at the top of my page.html.twig template:
<div class="alert alert-primary">
{{ drupal_token('node:title', {node: node}) }}<br />
{{ drupal_token('node:menu-link:parents', {node: node}) }}<hr />
{{ drupal_token('node:source:title', {node: node}) }}<br />
{{ drupal_token('node:source:menu-link:parents', {node: node}) }}
</div>
I have the following English Menu:
-Home
-What
--About
On the "About" page, in English, I therefore see "About", "What", "About", and "What"
The menu also exists in French:
-Home
-Quoi
--Nous
On the "Nous" page (the translation of "About"), I would expect to see "Nous", "Quoi", "About", "What".
But instead I see "Nous", "Quoi", "About", "Quoi", with the value of [node:source:menu-link:parents] being incorrect
This would suggest that the token path for [node:source:menu-links] is not looking at the source translation, and is instead giving the same output as [node:menu-links] with the current language menu links provided.
Is there an alternative token that can be used, or does this require a patch?
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3105028_defaultLanguage_menu_links.patch | 958 bytes | pgrandeg |
Issue fork token-3105028
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
philkay commentedAs we are looking to have the same URLs for English and French pages (/en/what/about and /fr/what/about), I tried looking at [node:source:url:path].
[node:source:url:absolute]
EN: http://localhost/drupal/en/what/about
FR: http://localhost/drupal/en/what/about
[node:source:url:path]
EN: /what/about
FR: /quoi/about
So it looks like the node:source:url:path is having the same issue as node:source:menu-links.
Comment #3
philkay commentedComment #4
pgrandeg commentedHello,
Same issue here. We are trying to keep URLs on original version for every language. Example:
http://localhost/en/parent/child
http://localhost/es/parent/child
And we are getting:
http://localhost/en/parent/child
http://localhost/es/padre/child
This is the token string we are using in our pattern: [node:source:menu-link:parents]/[node:source:title]
Could anyone advice us please?
Thank you in advance
Comment #5
pgrandeg commentedHello,
It would be improved by mantainers, but it still works.
I hope it helps
Comment #6
nwom commentedSetting to Needs Review, since a patch is attached.
Comment #7
bohus ulrychHello @pgrandeg
thanks for patch #5, seems to be working well - tested with D8.9.14
Comment #9
bboty commentedThank you, the patch has been working well on my client's website for 3 years now.
Comment #10
bboty commentedComment #11
berdirthis makes the assumption that the source is the same as the default translation, but that's necessarily the case.
What should be done instead I think is that the node:source token needs to update the langcode option to match its active language, that should be passed through both to [node:source:menu-link] (which this patch doesn't yet handle) and nested tokens.
Also, tests would be great, but source tests are quite lacking as we don't actually add translations, so it can't really be verified that this works.
Comment #13
hswong3i commentedComment #14
berdirThis changes langcode for all tokens, that's not OK.
This needs to be fixed where source gets passed through, with getUntranslated(), this is done correctly for nodes and needs to be the same here.
Comment #15
santanu mondal commentedComment #16
santanu mondal commented