Skip to main content

The recent version of Drupal 8 does not handle the display of the language code in the language switcher via the administration.

How do I display EN or FR in the Drupal 8 selector?

If you want to display "EN" or "FR" in your language switcher instead of "English" or "Français",  copy the following code into your .theme file. Change "nametheme" to your Drupal theme name's

function nomtheme_preprocess_links__language_block(&$variables) { 
  foreach ($variables['links'] as $i => $link) { 
    // @var \Drupal\language\Entity\ConfigurableLanguage $linkLanguage 
    $linkLanguage = $link['link']['#options']['language']; 
    $variables['links'][$i]['link']['#title'] = $linkLanguage->get('id'); 
  } 
}

Let's discuss your project

Contact us

  •  + 32 (0) 10 49 51 00
  •  info@expert-it.com