By editor, 6 November, 2015 Question Hur får man den för tillfället valda språket (aktuell sida eller användaren språk) programmatiskt i Drupal8 ? Drupal 8 //för Att få den språksyn-kod:$language = \Drupal::languageManager()->getCurrentLanguage()->getId(); //för Att få språket namn:$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"?