Token translation

Created on 21 October 2024, 25 days ago

Problem/Motivation

We needed to display node title as previous or next link text so we used token [node:title] but it was only returning default node translation on all languages.

Steps to reproduce

Create a drupal with multiple languages
Create a few nodes and translate them into different languages
Create a entity page view of these nodes
Set the prev and next link to display [node:title]
Navigate this view on different language
Observe that view title is always displayed in default language

Proposed resolution

Use the langcode parameter in the replace() method of Token.
For my use case I simply add this is the detokenize() method of the EntityPager.php class

    $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();

    return $this->token->replace($string, $data, ['langcode' => $langcode, 'clear' => TRUE]);

While it is OK for me, it would be best to detect view language configuration, wether it is in a specific language or interface text language selected for page.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇧🇪Belgium davidiio

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024