How to get the current language in Drupal 8 | Drupal 8

How to get the current language in Drupal 8

Submitted by editor on Fri, 11/06/2015 - 10:57
Question

How to get the currently selected language (current page or user language) programmatically in Drupal8 ?

Drupal 8

//To get the lanuage code:
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();

//To get the language name:
$language =  \Drupal::languageManager()->getCurrentLanguage()->getName();

 

Drupal 7

global $language;
$language=$language->language;

Comments

Navneet Singh (not verified)

Sun, 01/15/2017 - 10:18

Drupal 7:

global $language;
// return lang code;
return $language->language;

Drupal 8:

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

Add new comment