Hide unnecessary links from language switcher viewing untranslated nodes

Created on 16 March 2017, over 7 years ago
Updated 5 May 2023, over 1 year ago

The core language switcher lists all enabled languages even when viewing a node that is not translated to those languages.

The behaviour I would expect is to hide all the languages that specific node isn't translated to, or make it an option from the language switcher block settings.

For the moment, in case anybody stomps on the same behavior and isn't happy with it, a workaround could be implementing something like this in a theme:

  function THEMENAME_preprocess_links__language_block(&$variables) {
    $node = \Drupal::routeMatch()->getParameter('node');
    if(!$node) {
        return;
    }
    foreach(array_keys($variables['links']) as $lang) {
      if(!$node->hasTranslation($lang)) {
        unset($variables['links'][$lang]);
      }
    }
  }
Feature request
Status

Active

Version

10.1

Component
Language system 

Last updated about 15 hours ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇮🇹Italy entuland

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024