Change record status: 
Introduced in branch: 

Drupal 6 used to have a $language global to signify *the* page language. In Drupal 7 this was extended to several language types, so $language, $language_content and $language_url are the three built-in language contexts/globals. Drupal 8 is about to introduce a context system (see WSCCI) and the language values need to be namespaced properly to group together. Also, the use of $language as a global made it dangerous to use $language in a local context (eg. inside methods, functions) because the possibility to clash with the global and overwrite the value. There was no $account vs. $user as in Drupal 7.

In Drupal 8 Globals are handled by the dependency injection system. The 'language_manager' (accessible via Drupal::languageManager() to procedural code) service can be used to retrieve a language object of a given type, e.g. Drupal\Core\Language::TYPE_INTERFACE. That is also the default argument for the getLanguage() method, the other types provided by core are Drupal\Core\Language::TYPE_CONTENT and Drupal\Core\Language::TYPE_URL.

Drupal 7:

global $language;
$output = t('You speak %name', array('%name' => $language->name));

Drupal 8:

$language = \Drupal::languageManager()->getCurrentLanguage();
$output = t('You speak %name', array('%name' => $language->name));
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other updates done


jenlampton’s picture

*edit* never mind, I can see from here that it's already noted that we need to update the docs :)