n Get The Current Language in Drupal 8 | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
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