How to get current language in Drupal 8

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

 

Get current language code in Drupal 8:

$language = \Drupal::languageManager()->getCurrentLanguage()->getId();

Get current language name in Drupal 8:

$language = \Drupal::languageManager()->getCurrentLanguage()->getName();

Get all enabled languages in Drupal 8:

$languages = \Drupal::languageManager()->getLanguages();

 

 

Tags