function language_list
Returns a list of installed languages, indexed by the specified key.
Parameters
$field: (optional) The field to index the list with.
Return value
An associative array, keyed on the values of $field.
- If $field is 'weight' or 'enabled', the array is nested, with the outer array's values each being associative arrays with language codes as keys and language objects as values.
- For all other values of $field, the array is only one level deep, and the array's values are language objects.
47 calls to language_list()
- field_content_languages in modules/
field/ field.multilingual.inc - Returns available content languages.
- language_fallback_get_candidates in includes/
language.inc - Returns the possible fallback languages ordered by language weight.
- language_negotiation_get_switch_links in includes/
language.inc - Returns the language switch links for the given language.
- language_provider_invoke in includes/
language.inc - Helper function used to cache the language negotiation providers results.
- LocaleCommentLanguageFunctionalTest::testCommentLanguage in modules/
locale/ locale.test - Test that comment language is properly set.
14 string references to 'language_list'
- LocaleCommentLanguageFunctionalTest::testCommentLanguage in modules/
locale/ locale.test - Test that comment language is properly set.
- LocaleConfigurationTest::testLanguageConfiguration in modules/
locale/ locale.test - Functional tests for adding, editing and deleting languages.
- LocaleTranslationFunctionalTest::testJavaScriptTranslation in modules/
locale/ locale.test - LocaleUILanguageNegotiationTest::testUILanguageNegotiation in modules/
locale/ locale.test - Tests for language switching by URL path.
- LocaleUrlRewritingTest::setUp in modules/
locale/ locale.test - Sets up a Drupal site for running functional and integration tests.
File
-
includes/
bootstrap.inc, line 3118
Code
function language_list($field = 'language') {
$languages =& drupal_static(__FUNCTION__);
// Init language list
if (!isset($languages)) {
if (drupal_multilingual() || module_exists('locale')) {
$languages['language'] = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC')->fetchAllAssoc('language');
// Users cannot uninstall the native English language. However, we allow
// it to be hidden from the installed languages. Therefore, at least one
// other language must be enabled then.
if (!$languages['language']['en']->enabled && !variable_get('language_native_enabled', TRUE)) {
unset($languages['language']['en']);
}
}
else {
// No locale module, so use the default language only.
$default = language_default();
$languages['language'][$default->language] = $default;
}
}
// Return the array indexed by the right field
if (!isset($languages[$field])) {
$languages[$field] = array();
foreach ($languages['language'] as $lang) {
// Some values should be collected into an array
if (in_array($field, array(
'enabled',
'weight',
))) {
$languages[$field][$lang->{$field}][$lang->language] = $lang;
}
else {
$languages[$field][$lang->{$field}] = $lang;
}
}
}
return $languages[$field];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.