Commit 82cb7cf5 authored by Dries's avatar Dries

- Patch #1414314 by Gábor Hojtsy, tstoeckler: make node and path depend on...

- Patch #1414314 by Gábor Hojtsy, tstoeckler: make node and path depend on language module only for language support, get rid of locale_language_name().
parent 823ff6a1
......@@ -2703,6 +2703,41 @@ function language_list($only_enabled = FALSE) {
return $only_enabled ? $languages['enabled'] : $languages['all'];
}
/**
* Loads a language object from the database.
*
* @param $langcode
* The language code.
*
* @return
* A fully-populated language object or FALSE.
*/
function language_load($langcode) {
$languages = language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
}
/**
* Produced the printed name for a language for display.
*
* @param $langcode
* The language code.
*
* @return
* The printed name of the language.
*/
function language_name($langcode) {
if ($langcode == LANGUAGE_NONE) {
return t('None');
}
if ($language = language_load($langcode)) {
return $language->name;
}
return t('Unknown (@langcode)', array('@langcode' => $langcode));
}
/**
* Returns the default language used on the site.
*
......
......@@ -100,20 +100,6 @@ function language_theme() {
);
}
/**
* Loads a language object from the database.
*
* @param $langcode
* The language code.
*
* @return
* A fully-populated language object or FALSE.
*/
function language_load($langcode) {
$languages = language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
}
/**
* API function to add or update a language.
*
......
......@@ -297,7 +297,6 @@ function locale_form_alter(&$form, &$form_state, $form_id) {
function locale_form_node_form_alter(&$form, &$form_state) {
if (isset($form['#node']->type) && locale_multilingual_node_type($form['#node']->type)) {
$languages = language_list(TRUE);
$language_options = array(LANGUAGE_NONE => t('Language neutral'));
foreach ($languages as $langcode => $language) {
$language_options[$langcode] = $language->name;
}
......@@ -306,6 +305,8 @@ function locale_form_node_form_alter(&$form, &$form_state) {
'#title' => t('Language'),
'#default_value' => (isset($form['#node']->language) ? $form['#node']->language : ''),
'#options' => $language_options,
'#empty_value' => LANGUAGE_NONE,
'#empty_option' => t('- None -'),
);
}
// Node type without language selector: assign the default for new nodes
......@@ -768,15 +769,6 @@ function locale_get_plural($count, $langcode = NULL) {
}
/**
* Returns a language name.
*/
function locale_language_name($langcode) {
// Consider enabled languages only.
$languages = language_list(TRUE);
return ($langcode && isset($languages[$langcode])) ? $languages[$langcode]->name : t('All');
}
/**
* Implements hook_modules_installed().
*/
......
......@@ -107,14 +107,14 @@ function node_filters() {
// Language filter if the site is multilingual.
if (language_multilingual()) {
$languages = language_list(TRUE);
$language_options = array(LANGUAGE_NONE => t('Language neutral'));
$language_options = array(LANGUAGE_NONE => t('- None -'));
foreach ($languages as $langcode => $language) {
$language_options[$langcode] = $language->name;
}
$filters['language'] = array(
'title' => t('language'),
'options' => array(
'[any]' => t('any'),
'[any]' => t('- Any -'),
) + $language_options,
);
}
......@@ -173,7 +173,7 @@ function node_filter_form() {
$value = $value->name;
}
elseif ($type == 'language') {
$value = $value == LANGUAGE_NONE ? t('Language neutral') : module_invoke('locale', 'language_name', $value);
$value = language_name($value);
}
else {
$value = $filters[$type]['options'][$value];
......@@ -446,7 +446,7 @@ function node_admin_nodes() {
'changed' => array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc')
);
if ($multilanguage) {
$header['language'] = array('data' => t('Language'), 'field' => 'n.language');
$header['language_name'] = array('data' => t('Language'), 'field' => 'n.language');
}
$header['operations'] = array('data' => t('Operations'));
......@@ -498,12 +498,7 @@ function node_admin_nodes() {
'changed' => format_date($node->changed, 'short'),
);
if ($multilanguage) {
if ($node->language == LANGUAGE_NONE || isset($languages[$node->language])) {
$options[$node->nid]['language'] = $node->language == LANGUAGE_NONE ? t('Language neutral') : $languages[$node->language]->name;
}
else {
$options[$node->nid]['language'] = t('Undefined language (@langcode)', array('@langcode' => $node->language));
}
$options[$node->nid]['language_name'] = language_name($node->language);
}
// Build a list of all the accessible operations for the current node.
$operations = array();
......
......@@ -14,9 +14,10 @@
function path_admin_overview($keys = NULL) {
// Add the filter form above the overview table.
$build['path_admin_filter_form'] = drupal_get_form('path_admin_filter_form', $keys);
// Enable language column if locale is enabled or if we have any alias with language
// Enable language column if language.module is enabled or if we have any
// alias with a language.
$alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE langcode <> :langcode', 0, 1, array(':langcode' => LANGUAGE_NONE))->fetchField();
$multilanguage = (module_exists('locale') || $alias_exists);
$multilanguage = (module_exists('language') || $alias_exists);
$header = array();
$header[] = array('data' => t('Alias'), 'field' => 'alias', 'sort' => 'asc');
......@@ -44,7 +45,7 @@ function path_admin_overview($keys = NULL) {
$row['data']['alias'] = l($data->alias, $data->source);
$row['data']['source'] = l($data->source, $data->source, array('alias' => TRUE));
if ($multilanguage) {
$row['data']['langcode'] = module_invoke('locale', 'language_name', $data->langcode);
$row['data']['language_name'] = language_name($data->langcode);
}
$operations = array();
......@@ -130,10 +131,9 @@ function path_admin_form($form, &$form_state, $path = array('source' => '', 'ali
'#required' => TRUE,
);
// A hidden value unless locale module is enabled.
if (module_exists('locale')) {
// A hidden value unless language.module is enabled.
if (module_exists('language')) {
$languages = language_list(TRUE);
$language_options = array(LANGUAGE_NONE => t('All languages'));
foreach ($languages as $langcode => $language) {
$language_options[$langcode] = $language->name;
}
......@@ -142,9 +142,11 @@ function path_admin_form($form, &$form_state, $path = array('source' => '', 'ali
'#type' => 'select',
'#title' => t('Language'),
'#options' => $language_options,
'#empty_value' => LANGUAGE_NONE,
'#empty_option' => t('- None -'),
'#default_value' => $path['langcode'],
'#weight' => -10,
'#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set for <em>All languages</em>.'),
'#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as <em>- None -</em>.'),
);
}
else {
......@@ -194,7 +196,8 @@ function path_admin_form_validate($form, &$form_state) {
$source = drupal_get_normal_path($source);
$alias = $form_state['values']['alias'];
$pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0;
// Language is only set if locale module is enabled, otherwise save for all languages.
// Language is only set if language.module is enabled, otherwise save for all
// languages.
$langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LANGUAGE_NONE;
$has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND langcode = :langcode", array(
......
......@@ -139,7 +139,7 @@ function translation_form_node_form_alter(&$form, &$form_state) {
// might need to distinguish between enabled and disabled languages, hence
// we divide them in two option groups.
if ($translator_widget) {
$options = array($groups[1] => array(LANGUAGE_NONE => t('Language neutral')));
$options = array($groups[1] => array(LANGUAGE_NONE => t('- None -')));
foreach (array(1, 0) as $status) {
$group = $groups[$status];
foreach ($grouped_languages[$status] as $langcode => $language) {
......
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