Question
How to get the currently selected language (current page or user language) programmatically in Drupal8 ?
Drupal 8
//To get the lanuage code:
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
//To get the language name:
$language = \Drupal::languageManager()->getCurrentLanguage()->getName();
Drupal 7
global $language;
$language=$language->language;
Comments
To get all enabled language…
To get all enabled language in drupal 8 :
\Drupal::languageManager()->getLanguages();
This may be helpful to any one.
Yes
Yes, Thank you :)
Replacement of global $language
Drupal 7:
global $language;
// return lang code;
return $language->language;
Drupal 8:
return $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
Thanks its work for me :)
Thanks its work for me :)
Thank you! I couldn't figure…
Thank you! I couldn't figure out how to call this.
thanks
thank you worked like a charm
Add new comment