Drupal 8: Get The Current Language

Tuesday, April 26, 2016 - 16:27

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();
Category: 
philipnorton42's picture

Philip Norton

Phil is the founder and administrator of #! code and is an IT professional working in the North West of the UK.
Google+ | Twitter

Comments

It,s really helpful. Thank you so much.

Add new comment