Get current language langcode in drupal 8

You often need to get the current language in your Drupal 8 custom modules or theme. Here's how to get it:

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

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!