Commit dc29547a authored by Dries's avatar Dries
Browse files

- Patch #1265700 by Gábor Hojtsy: Little modernization of language_default().

parent d06e11ce
......@@ -2559,14 +2559,28 @@ function language_list($field = 'language') {
}
/**
* Default language used on the site
* Default language used on the site.
*
* @param $property
* Optional property of the language object to return
*/
function language_default($property = NULL) {
$language = variable_get('language_default', (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''));
return $property ? $language->$property : $language;
* @return
* A language object.
*/
function language_default() {
return variable_get(
'language_default',
(object) array(
'language' => 'en',
'name' => 'English',
'native' => 'English',
'direction' => 0,
'enabled' => 1,
'plurals' => 0,
'formula' => '',
'domain' => '',
'prefix' => '',
'weight' => 0,
'javascript' => ''
)
);
}
/**
......
......@@ -709,7 +709,7 @@ function _locale_rebuild_js($langcode = NULL) {
// Update the default language variable if the default language has been altered.
// This is necessary to keep the variable consistent with the database
// version of the language and to prevent checking against an outdated hash.
$default_langcode = language_default('language');
$default_langcode = language_default()->language;
if ($default_langcode == $language->language) {
$default = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $default_langcode))->fetchObject();
variable_set('language_default', $default);
......
......@@ -228,7 +228,7 @@ function field_valid_language($langcode, $default = TRUE) {
return $langcode;
}
global $language_content;
return $default ? language_default('language') : $language_content->language;
return $default ? language_default()->language : $language_content->language;
}
/**
......
......@@ -52,7 +52,7 @@ function locale_languages_overview_form() {
'#title' => t('Default language'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => language_default('language'),
'#default_value' => language_default()->language,
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
......@@ -392,7 +392,7 @@ function locale_languages_edit_form_validate($form, &$form_state) {
if (!empty($form_state['values']['domain']) && $duplicate = db_query("SELECT language FROM {languages} WHERE domain = :domain AND language <> :language", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchField()) {
form_set_error('domain', t('The domain (%domain) is already tied to a language (%language).', array('%domain' => $form_state['values']['domain'], '%language' => $duplicate->language)));
}
if (empty($form_state['values']['prefix']) && language_default('language') != $form_state['values']['langcode'] && empty($form_state['values']['domain'])) {
if (empty($form_state['values']['prefix']) && language_default()->language != $form_state['values']['langcode'] && empty($form_state['values']['domain'])) {
form_set_error('prefix', t('Only the default language can have both the domain and prefix empty.'));
}
if (!empty($form_state['values']['prefix']) && $duplicate = db_query("SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchField()) {
......@@ -439,7 +439,7 @@ function locale_languages_delete_form($form, &$form_state, $langcode) {
drupal_goto('admin/config/regional/language');
}
if (language_default('language') == $langcode) {
if (language_default()->language == $langcode) {
drupal_set_message(t('The default language cannot be deleted.'));
drupal_goto('admin/config/regional/language');
}
......
......@@ -477,7 +477,7 @@ class PathMonolingualTestCase extends DrupalWebTestCase {
// Verify that French is the only language.
$this->assertFalse(drupal_multilingual(), t('Site is mono-lingual'));
$this->assertEqual(language_default('language'), 'fr', t('French is the default language'));
$this->assertEqual(language_default()->language, 'fr', t('French is the default language'));
// Set language detection to URL.
$edit = array('language[enabled][locale-url]' => TRUE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment