Skip to main content
Category:

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();

 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook