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

 

Tags :

Comments

Add new comment

Restricted HTML

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

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

Web Posts

Search

Page Facebook