My site example.com is configured with 2 languages, Norwegian and Finnish. All nodes are written in Norwegian, and some are translated to Finnish.
The front page view is configured to include teasers from all nodes from the default language (Norwegian), that is:
* Filter: Content: Translation language (= Site's default language (Norwegian Bokmål))
and render them in the language of the selcted interface, that is:
* Rendering Language: Interface text language selected for page

The result of this is that the front page shows teasers from all nodes in Norwegian if the user has selected Norwegian as interface text language. If the user selects Finnish as his interface text, the front page shows teasers from all nodes - the ones that are translated in Finnish, and the ones that are not in Norwegian. And this is how I want example.com to work.

The problem occurs when the user now clicks on one of the titles (or read more link) of the nodes that are not translated. Because this will link to the node without the prefix for Finnish (fi), and effectively switch the interface language.

Example:
example.com/node/4 is not translated to Finnish. So visiting example.com/fi/node/4 shows the node in Norwegian, but with Finnish interface text (menu etc).
When visiting example.com/fi the user sees teasers of all nodes, the ones that are translated in Finnish, and the ones that are not in Norwegian.
Clicking on the title of node 4 takes the user to example.com/node/4 which correctly shows node 4 in Norwegian, but also swithces the interface language to Norwegian (which is undesired). I would expect the link to take the user to example.com/fi/node/4.

FYI: If adding a menu entry for this node, this menu entry behaves as I expect (in other words linking to example.com/fi/node/4 if the user has selected Finnish as interface text language)

I've tried tons of combinations of settings for the front page view, language setup, content type setup etc., but have not been able to achieve my goal. Any input on this would be highly appreciated :)

CommentFileSizeAuthor
#2 viewConfig.png18.63 KBroald
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

roald created an issue. See original summary.

roald’s picture

FileSize
18.63 KB
nplowman’s picture

Running into this same issue.
This seems to be a bug, as it behaves as you are describing if you are using a Rendered Entity instead of Fields as the View type.

For whatever reason, it doesn't handle fallback languages correctly when using Fields.

matt_paz’s picture

Version: 8.1.x-dev » 8.4.x-dev

@roald Were you able to identify a fix/workaround for this?

tetranz’s picture

I'm not sure if this is a bug or not. It seems like it is. If nothing else it's inconsistent because I notice that if you render the nodes and include author links, the author links include the language prefix while the main node link does not.

Here's a workaround. Put this in a module or theme.

function mymoduleortheme_preprocess_node(&$variables) {
  /** @var \Drupal\node\Entity\Node $node */
  $node = $variables['node'];

  $variables['url'] = $node->toUrl('canonical', [
    'language' => \Drupal::languageManager()->getCurrentLanguage(),
  ]);
}

It overrides this in template_preprocess_node in node.module

  $variables['url'] = $node->url('canonical', [
    'language' => $node->language(),
  ]);

That would be a simple patch but I'm not sure what other effects it might have. I guess I could try it and see what tests fail.

Version: 8.4.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nikosnikos’s picture

Thanks @tetranz ! I didn't test it in drupal 8 but with drupal 9 it works with:
$variables['url'] = !$node->isNew() ? $node->toUrl('canonical', ['language' => \Drupal::languageManager()->getCurrentLanguage()])->toString() : NULL;

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.