How to get current language in Drupal 8

Posted on Thursday, April 6, 2017

Here is the quick code snippet of how we can get the current language in Drupal 8 form multilanguage sites.

 

Get current language code in Drupal 8:

<?php $language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId(); ?>

Get current language name in Drupal 8:

<?php $language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getName(); ?>

Get all enabled languages in Drupal 8:

<?php $languages = \Drupal::languageManager()-&gt;getLanguages(); ?>

Tags

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.