Get all languas of the site in Drupal 8 | Drupal 8

Get all languas of the site in Drupal 8

Submitted by editor on Tue, 12/01/2015 - 18:03
Question

How to get languages available on the site on Drupal 8 ?

To get languages in English:
$site_languages = \Drupal::languageManager()->getLanguages();

To get languages in native language:
$site_languages = \Drupal::languageManager()->getNativeLanguages();

foreach ($site_languages as $languagecode => $language) {
   drupal_set_message($languagecode . " - " . $language->getName() );
}

Add new comment