How to get current language in Drupal 8

Posted on Thursday, April 6, 2017

Here is the quick code snippet of how we can get the current language in Drupal 8 form multilanguage sites.

 

Get current language code in Drupal 8:

<?php $language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId(); ?>

Get current language name in Drupal 8:

<?php $language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getName(); ?>

Get all enabled languages in Drupal 8:

<?php $languages = \Drupal::languageManager()-&gt;getLanguages(); ?>

Tags

Disqus Comments