By editor, 6 November, 2015 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; Tags Drupal 8 Code Translation User Add new comment Comments7 You must have JavaScript enabled to use this form. Your name Subject Comment About text formats Plain text No HTML tags allowed. Lines and paragraphs break automatically. Web page addresses and email addresses turn into links automatically. To get all enabled languageā¦ To get all enabled language in drupal 8 : \Drupal::languageManager()->getLanguages(); This may be helpful to any one. Reply Yes Yes, Thank you :) Reply Replacement of global $language Drupal 7: global $language; // return lang code; return $language->language; Drupal 8: return $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); Reply Thanks its work for me :) Thanks its work for me :) Reply Thank you! I couldn't figureā¦ Thank you! I couldn't figure out how to call this. Reply thanks thank you worked like a charm Reply Current language in current language And how do I get the current language in the current language, not "French" but "FranƧais"? Reply
To get all enabled languageā¦ To get all enabled language in drupal 8 : \Drupal::languageManager()->getLanguages(); This may be helpful to any one. Reply
Replacement of global $language Drupal 7: global $language; // return lang code; return $language->language; Drupal 8: return $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); Reply
Current language in current language And how do I get the current language in the current language, not "French" but "FranƧais"? Reply
Comments7
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
Current language in current language
And how do I get the current language in the current language, not "French" but "FranƧais"?