Identifies language from configuration.
$languages: An array of valid language objects.
A valid language code on success, FALSE otherwise.
function language_from_selected($languages) {
$langcode = (string) config('language.negotiation')
->get('selected_langcode');
// Replace the site's default langcode by its real value.
if ($langcode == 'site_default') {
$langcode = language_default()->langcode;
}
return isset($languages[$langcode]) ? $langcode : language_default()->langcode;
}