Drupal 8: Get The Current Language

To get the currently selected language on a Drupal 8 site you need to run the following.

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

This will return the 2 character ISO language code for the language. So for English this would be "en".

To get the language name instead of the language code use this.

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


It,s really helpful. Thank you so much.

Short, cool and informative. Thank you!


Small remark,

To get the currently selected language for content :

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



Thank you Philip. I did not have the interface translation enabled so your snipped was always returning the default language. The snipped posted by "tty11" worked. Thanks tty11 :), however I will make a small change to it. Drupal couldn't find "LanguageInterface" in my theme's preprocess function, I had to provide namespace too as follows

$language = \Drupal::languageManager()->getCurrentLanguage(\Drupal\Core\Language\LanguageInterface::TYPE_CONTENT)->getId();



Thanks Ejay. I wrote this post during my first few weeks of Drupal 8 development. I've since learned a lot about how the language manager works so there are probably a few contextual issues with my original snippet :)

Philip Norton

Add new comment

The content of this field is kept private and will not be shown publicly.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.