4

I have a View that is list of a content type using fields. (I am also using a Relationship and a Contextual Filter, btw.)

One of those fields is "link to content".

The content type is translatable. The View is filtered by Translation language (= Interface text language selected for page). In my secondary language (German) only nodes with a translation are shown. So far, so good.

The rendering language is set to: Interface text language selected for page.

However, the rendered rows always link to the default language (/en), even when the rest of the page is rendered in the secondary language (de).

What can I do to get the rows to render the links in the correct language?

4

It's a bug and it's being worked on, the solution is provided and it's currently labeled as Needs review. Perhaps you can apply the patch and test yourself:

Entity Links fields does not have translation support

In Drupal 8.4 and earlier versions it was possible to use the workaround of Path field and using Custom text field to construct the link:

<a href="{{ path }}">{% trans %} View more {% endtrans %}</a>

The Path field output correctly translated links with correct path prefix, see here: Translate Content: Link to Content field on Views in Drupal 8. But in Drupal 8.5 the Path field is no longer supported, so you have to patch or wait for the update to gets released.

2

Add 2 fields to your view:

  1. a "Content: Node ID (Node ID)" field
  2. a "Content: Translation language (Translation language)" field.

Exclude the "Content: Node ID" field from display.


Override the output of this field with custom text:

{% trans %} View more {% endtrans %}

Rewrite the "Content: Translation Language" field as a custom link:

{{ langcode_value }}/node/{{ nid }}

Then go to admin/config/regional/translate.

You may translate View more in any desired language: FILTER TRANSLATABLE STRINGS (View more) and translate it according to language

0

The Answer by Jturpin helped me fix this issue. In addition to that you could shorten

{% trans %} View more {% endtrans %}

to

{{'View more'|t}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.