Question
How to get current language in Drupal 8?
Solution
To get the current language on a Drupal 8 site you need to run the following code
/**
* this will return "en", "fr" ...
*/
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
To get the language name instead of the language code use this.
/**
* this will return "english", "french" ...
*/
$language = \Drupal::languageManager()->getCurrentLanguage()->getName();