Commit b956b400 authored by Dries's avatar Dries

- Patch #1439686 by tstoeckler: rename language property to langcode.

parent 18c1d673
......@@ -454,8 +454,8 @@ class TextTranslationTestCase extends DrupalWebTestCase {
$langcode = LANGUAGE_NONE;
$body = $this->randomName();
$edit = array(
"title" => $this->randomName(),
"language" => 'en',
'title' => $this->randomName(),
'langcode' => 'en',
"body[$langcode][0][value]" => $body,
);
......@@ -487,7 +487,7 @@ class TextTranslationTestCase extends DrupalWebTestCase {
$title = $this->randomName();
$edit = array(
'title' => $title,
'language' => 'en',
'langcode' => 'en',
);
$this->drupalPost('node/add/article', $edit, t('Save'));
......
......@@ -292,13 +292,13 @@ function locale_field_node_form_submit($form, &$form_state) {
foreach (field_info_instances('node', $bundle) as $instance) {
$field_name = $instance['field_name'];
$field = field_info_field($field_name);
$previous_language = $form[$field_name]['#language'];
$previous_langcode = $form[$field_name]['#language'];
// Handle a possible language change: new language values are inserted,
// previous ones are deleted.
if ($field['translatable'] && $previous_language != $node->language) {
$form_state['values'][$field_name][$node->language] = $node->{$field_name}[$previous_language];
$form_state['values'][$field_name][$previous_language] = array();
if ($field['translatable'] && $previous_langcode != $node->langcode) {
$form_state['values'][$field_name][$node->langcode] = $node->{$field_name}[$previous_langcode];
$form_state['values'][$field_name][$previous_langcode] = array();
}
}
}
......@@ -1085,15 +1085,15 @@ function locale_form_system_file_system_settings_alter(&$form, $form_state) {
* Implements MODULE_preprocess_HOOK().
*/
function locale_preprocess_node(&$variables) {
if ($variables['language'] != LANGUAGE_NONE) {
if ($variables['langcode'] != LANGUAGE_NONE) {
global $language_interface;
$node_language = language_load($variables['language']);
$node_language = language_load($variables['langcode']);
if ($node_language->langcode != $language_interface->langcode) {
// If the node language was different from the page language, we should
// add markup to identify the language. Otherwise the page language is
// inherited.
$variables['attributes_array']['lang'] = $variables['language'];
$variables['attributes_array']['lang'] = $variables['langcode'];
if ($node_language->direction != $language_interface->direction) {
// If text direction is different form the page's text direction, add
// direction information as well.
......
......@@ -2002,7 +2002,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
// Verify language selection appears on add "Basic page" form.
$this->drupalGet('node/add/page');
// Verify language select list is present.
$this->assertFieldByName('language', NULL, t('Language select present on add Basic page form.'));
$this->assertFieldByName('langcode', NULL, t('Language select present on add Basic page form.'));
// Ensure enabled language appears.
$this->assertText($name, t('Enabled language present.'));
// Ensure disabled language doesn't appear.
......@@ -2015,7 +2015,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
'type' => 'page',
'title' => $node_title,
'body' => array($langcode => array(array('value' => $node_body))),
'language' => $langcode,
'langcode' => $langcode,
);
$node = $this->drupalCreateNode($edit);
// Edit the content and ensure correct language is selected.
......@@ -2024,7 +2024,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
$this->assertRaw('<option value="' . $langcode . '" selected="selected">' . $name . '</option>', t('Correct language selected.'));
// Ensure we can change the node language.
$edit = array(
'language' => 'en',
'langcode' => 'en',
);
$this->drupalPost($path, $edit, t('Save'));
$this->assertRaw(t('%title has been updated.', array('%title' => $node_title)), t('Basic page content updated.'));
......@@ -2107,7 +2107,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
'type' => 'article',
'title' => $node_title,
'body' => array($langcode => array(array('value' => $node_body))),
'language' => $langcode,
'langcode' => $langcode,
'promote' => 1,
);
return $this->drupalCreateNode($edit);
......@@ -2575,7 +2575,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase {
$edit = array();
$edit[$title_key] = $title_value;
$edit[$body_key] = $body_value;
$edit['language'] = 'en';
$edit['langcode'] = 'en';
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the node exists in the database.
......@@ -2589,7 +2589,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase {
$this->drupalGet("node/$node->nid/edit");
$edit = array(
$title_key => $this->randomName(8),
'language' => 'it'
'langcode' => 'it'
);
$this->drupalPost(NULL, $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit[$title_key]);
......@@ -2624,7 +2624,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase {
$edit = array();
$edit[$title_key] = $title_value;
$edit[$body_key] = $body_value;
$edit['language'] = 'en';
$edit['langcode'] = 'en';
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the node exists in the database.
......@@ -2706,7 +2706,7 @@ class LocaleCommentLanguageFunctionalTest extends DrupalWebTestCase {
$edit = array(
"title" => $title,
"body[$langcode_none][0][value]" => $this->randomName(),
"language" => $node_langcode,
"langcode" => $node_langcode,
);
$this->drupalPost("node/add/article", $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($title);
......
......@@ -435,7 +435,7 @@ function node_admin_nodes() {
// Enable language column if translation module is enabled or if we have any
// node with language.
$multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> :language", 0, 1, array(':language' => LANGUAGE_NONE))->fetchField());
$multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE langcode <> :langcode", 0, 1, array(':langcode' => LANGUAGE_NONE))->fetchField());
// Build the sortable table header.
$header = array(
......@@ -446,7 +446,7 @@ function node_admin_nodes() {
'changed' => array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc')
);
if ($multilanguage) {
$header['language_name'] = array('data' => t('Language'), 'field' => 'n.language');
$header['language_name'] = array('data' => t('Language'), 'field' => 'n.langcode');
}
$header['operations'] = array('data' => t('Operations'));
......@@ -481,7 +481,7 @@ function node_admin_nodes() {
$destination = drupal_get_destination();
$options = array();
foreach ($nodes as $node) {
$l_options = $node->language != LANGUAGE_NONE && isset($languages[$node->language]) ? array('language' => $languages[$node->language]) : array();
$l_options = $node->langcode != LANGUAGE_NONE && isset($languages[$node->langcode]) ? array('language' => $languages[$node->langcode]) : array();
$options[$node->nid] = array(
'title' => array(
'data' => array(
......@@ -498,7 +498,7 @@ function node_admin_nodes() {
'changed' => format_date($node->changed, 'short'),
);
if ($multilanguage) {
$options[$node->nid]['language_name'] = language_name($node->language);
$options[$node->nid]['language_name'] = language_name($node->langcode);
}
// Build a list of all the accessible operations for the current node.
$operations = array();
......
......@@ -32,7 +32,7 @@ function node_schema() {
'not null' => TRUE,
'default' => '',
),
'language' => array(
'langcode' => array(
'description' => 'The {language}.langcode of this node.',
'type' => 'varchar',
'length' => 12,
......@@ -541,6 +541,20 @@ function node_update_8001() {
}
}
/**
* Rename node.language field to node.langcode.
*/
function node_update_8002() {
$spec = array(
'description' => 'The {language}.langcode of this node.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
);
db_change_field('node', 'language', 'langcode', $spec);
}
/**
* @} End of "addtogroup updates-7.x-to-8.x"
* The next series of updates should start at 9000.
......
......@@ -1340,7 +1340,7 @@ function node_view($node, $view_mode = 'full', $langcode = NULL) {
'#theme' => 'node',
'#node' => $node,
'#view_mode' => $view_mode,
'#language' => $langcode,
'#langcode' => $langcode,
);
// Add contextual links for this node, except when the node is already being
......@@ -1724,7 +1724,7 @@ function node_search_execute($keys = NULL, $conditions = NULL) {
// Insert special keywords.
$query->setOption('type', 'n.type');
$query->setOption('language', 'n.language');
$query->setOption('langcode', 'n.langcode');
if ($query->setOption('term', 'ti.tid')) {
$query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
}
......@@ -1764,7 +1764,7 @@ function node_search_execute($keys = NULL, $conditions = NULL) {
'extra' => $extra,
'score' => $item->calculated_score,
'snippet' => search_excerpt($keys, $node->rendered),
'language' => $node->language,
'langcode' => $node->langcode,
);
}
return $results;
......@@ -2848,10 +2848,8 @@ function node_form_search_form_alter(&$form, $form_state) {
// Languages:
$language_options = array();
foreach (language_list() as $key => $entity) {
if ($entity->enabled) {
$language_options[$key] = $entity->name;
}
foreach (language_list(TRUE) as $langcode => $language) {
$language_options[$langcode] = $language->name;
}
if (count($language_options) > 1) {
$form['advanced']['language'] = array(
......@@ -4204,9 +4202,9 @@ function node_file_download_access($field, $entity_type, $entity) {
* Implements hook_language_delete().
*/
function node_language_delete($language) {
// On nodes with this language, unset the language
// On nodes with this language, unset the language.
db_update('node')
->fields(array('language' => ''))
->condition('language', $language->langcode)
->fields(array('langcode' => ''))
->condition('langcode', $language->langcode)
->execute();
}
......@@ -87,7 +87,7 @@ function node_add($type) {
global $user;
$types = node_type_get_types();
$node = (object) array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => LANGUAGE_NONE);
$node = (object) array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'langcode' => LANGUAGE_NONE);
drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)), PASS_THROUGH);
$output = drupal_get_form($type . '_node_form', $node);
......@@ -153,7 +153,7 @@ function node_form($form, &$form_state, $node) {
// Basic node information.
// These elements are just values so they are not even sent to the client.
foreach (array('nid', 'vid', 'uid', 'created', 'type', 'language') as $key) {
foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) {
$form[$key] = array(
'#type' => 'value',
'#value' => isset($node->$key) ? $node->$key : NULL,
......@@ -187,20 +187,20 @@ function node_form($form, &$form_state, $node) {
foreach ($languages as $langcode => $language) {
$language_options[$langcode] = $language->name;
}
$form['language'] = array(
$form['langcode'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#default_value' => (isset($node->language) ? $node->language : ''),
'#default_value' => (isset($node->langcode) ? $node->langcode : ''),
'#options' => $language_options,
'#empty_value' => LANGUAGE_NONE,
);
}
else {
$form['language'] = array(
$form['langcode'] = array(
'#type' => 'value',
// New nodes without multilingual support get the default language, old
// nodes keep their language if language.module is not available.
'#value' => !isset($form['#node']->nid) ? language_default()->langcode : $node->language,
'#value' => !isset($form['#node']->nid) ? language_default()->langcode : $node->langcode,
);
}
......@@ -358,7 +358,7 @@ function node_form($form, &$form_state, $node) {
}
$form += array('#submit' => array());
field_attach_form('node', $node, $form, $form_state, $node->language);
field_attach_form('node', $node, $form, $form_state, $node->langcode);
return $form;
}
......
......@@ -510,7 +510,7 @@ class NodeCreationTestCase extends DrupalWebTestCase {
'uid' => $this->loggedInUser->uid,
'name' => $this->loggedInUser->name,
'type' => 'page',
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
'title' => 'testing_transaction_exception',
);
......@@ -2190,7 +2190,7 @@ class NodeEntityFieldQueryAlter extends DrupalWebTestCase {
// Creating 4 nodes with an entity field so we can test that sort of query
// alter. All field values starts with 'A' so we can identify and fetch them
// in the node_access_test module.
$settings = array('language' => LANGUAGE_NONE);
$settings = array('langcode' => LANGUAGE_NONE);
for ($i = 0; $i < 4; $i++) {
$body = array(
'value' => 'A' . $this->randomName(32),
......@@ -2268,9 +2268,9 @@ class NodeTokenReplaceTestCase extends DrupalWebTestCase {
$tests['[node:type]'] = 'article';
$tests['[node:type-name]'] = 'Article';
$tests['[node:title]'] = check_plain($node->title);
$tests['[node:body]'] = _text_sanitize($instance, $node->language, $node->body[$node->language][0], 'value');
$tests['[node:summary]'] = _text_sanitize($instance, $node->language, $node->body[$node->language][0], 'summary');
$tests['[node:language]'] = check_plain($node->language);
$tests['[node:body]'] = _text_sanitize($instance, $node->langcode, $node->body[$node->langcode][0], 'value');
$tests['[node:summary]'] = _text_sanitize($instance, $node->langcode, $node->body[$node->langcode][0], 'summary');
$tests['[node:langcode]'] = check_plain($node->langcode);
$tests['[node:url]'] = url('node/' . $node->nid, $url_options);
$tests['[node:edit-url]'] = url('node/' . $node->nid . '/edit', $url_options);
$tests['[node:author]'] = check_plain(user_format_name($account));
......@@ -2289,9 +2289,9 @@ class NodeTokenReplaceTestCase extends DrupalWebTestCase {
// Generate and test unsanitized tokens.
$tests['[node:title]'] = $node->title;
$tests['[node:body]'] = $node->body[$node->language][0]['value'];
$tests['[node:summary]'] = $node->body[$node->language][0]['summary'];
$tests['[node:language]'] = $node->language;
$tests['[node:body]'] = $node->body[$node->langcode][0]['value'];
$tests['[node:summary]'] = $node->body[$node->langcode][0]['summary'];
$tests['[node:langcode]'] = $node->langcode;
$tests['[node:author:name]'] = user_format_name($account);
foreach ($tests as $input => $expected) {
......
......@@ -50,9 +50,9 @@ function node_token_info() {
'name' => t("Summary"),
'description' => t("The summary of the node's main body text."),
);
$node['language'] = array(
'name' => t("Language"),
'description' => t("The language the node is written in."),
$node['langcode'] = array(
'name' => t('Language code'),
'description' => t('The language code of the language the node is written in.'),
);
$node['url'] = array(
'name' => t("URL"),
......@@ -143,8 +143,8 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
}
break;
case 'language':
$replacements[$original] = $sanitize ? check_plain($node->language) : $node->language;
case 'langcode':
$replacements[$original] = $sanitize ? check_plain($node->langcode) : $node->langcode;
break;
case 'url':
......
......@@ -97,8 +97,8 @@ function path_form_node_form_alter(&$form, $form_state) {
$path = array();
if (!empty($form['#node']->nid)) {
$conditions = array('source' => 'node/' . $form['#node']->nid);
if ($form['#node']->language != LANGUAGE_NONE) {
$conditions['langcode'] = $form['#node']->language;
if ($form['#node']->langcode != LANGUAGE_NONE) {
$conditions['langcode'] = $form['#node']->langcode;
}
$path = path_load($conditions);
if ($path === FALSE) {
......@@ -109,7 +109,7 @@ function path_form_node_form_alter(&$form, $form_state) {
'pid' => NULL,
'source' => isset($form['#node']->nid) ? 'node/' . $form['#node']->nid : NULL,
'alias' => '',
'langcode' => isset($form['#node']->language) ? $form['#node']->language : LANGUAGE_NONE,
'langcode' => isset($form['#node']->langcode) ? $form['#node']->langcode : LANGUAGE_NONE,
);
$form['path'] = array(
......@@ -157,8 +157,8 @@ function path_form_element_validate($element, &$form_state, $complete_form) {
// originally assigned URL alias language.
// @todo Remove this after converting Path module to a field, and, after
// stopping Locale module from abusing the content language system.
if (isset($form_state['values']['language'])) {
form_set_value($element['langcode'], $form_state['values']['language'], $form_state);
if (isset($form_state['values']['langcode'])) {
form_set_value($element['langcode'], $form_state['values']['langcode'], $form_state);
}
$path = $form_state['values']['path'];
......@@ -189,7 +189,7 @@ function path_node_insert($node) {
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$path['source'] = 'node/' . $node->nid;
$path['langcode'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
$path['langcode'] = isset($node->langcode) ? $node->langcode : LANGUAGE_NONE;
path_save($path);
}
}
......@@ -210,7 +210,7 @@ function path_node_update($node) {
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$path['source'] = 'node/' . $node->nid;
$path['langcode'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
$path['langcode'] = isset($node->langcode) ? $node->langcode : LANGUAGE_NONE;
path_save($path);
}
}
......
......@@ -267,7 +267,7 @@ class PathLanguageTestCase extends DrupalWebTestCase {
// Edit the node to set language and path.
$edit = array();
$edit['language'] = 'en';
$edit['langcode'] = 'en';
$edit['path[alias]'] = $english_alias;
$this->drupalPost('node/' . $english_node->nid . '/edit', $edit, t('Save'));
......@@ -303,7 +303,7 @@ class PathLanguageTestCase extends DrupalWebTestCase {
drupal_static_reset('locale_url_outbound_alter');
drupal_static_reset('locale_language_url_rewrite_url');
$languages = language_list();
$url = url('node/' . $french_node->nid, array('language' => $languages[$french_node->language]));
$url = url('node/' . $french_node->nid, array('language' => $languages[$french_node->langcode]));
$this->assertTrue(strpos($url, $edit['path[alias]']), t('URL contains the path alias.'));
// Confirm that the alias works even when changing language negotiation
......@@ -353,17 +353,17 @@ class PathLanguageTestCase extends DrupalWebTestCase {
// drupal_lookup_path() has an internal static cache. Check to see that
// it has the appropriate contents at this point.
drupal_lookup_path('wipe');
$french_node_path = drupal_lookup_path('source', $french_alias, $french_node->language);
$french_node_path = drupal_lookup_path('source', $french_alias, $french_node->langcode);
$this->assertEqual($french_node_path, 'node/' . $french_node->nid, t('Normal path works.'));
// Second call should return the same path.
$french_node_path = drupal_lookup_path('source', $french_alias, $french_node->language);
$french_node_path = drupal_lookup_path('source', $french_alias, $french_node->langcode);
$this->assertEqual($french_node_path, 'node/' . $french_node->nid, t('Normal path is the same.'));
// Confirm that the alias works.
$french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->language);
$french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->langcode);
$this->assertEqual($french_node_alias, $french_alias, t('Alias works.'));
// Second call should return the same alias.
$french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->language);
$french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->langcode);
$this->assertEqual($french_node_alias, $french_alias, t('Alias is the same.'));
}
}
......
......@@ -853,7 +853,7 @@ class PollTranslateTestCase extends PollTestCase {
// Set the poll's first choice count to 200.
$edit['choice[chid:1][chvotes]'] = 200;
// Set the language to Dutch.
$edit['language'] = 'nl';
$edit['langcode'] = 'nl';
$this->drupalPost(NULL, $edit, t('Save'));
// Translate the Dutch poll.
......
......@@ -932,7 +932,7 @@ protected function drupalCreateNode($settings = array()) {
'sticky' => 0,
'type' => 'page',
'revisions' => NULL,
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
);
// Use the original node's created time for existing nodes.
......@@ -957,7 +957,7 @@ protected function drupalCreateNode($settings = array()) {
'value' => $this->randomName(32),
'format' => filter_default_format(),
);
$settings['body'][$settings['language']][0] += $body;
$settings['body'][$settings['langcode']][0] += $body;
$node = (object) $settings;
node_save($node);
......
......@@ -1617,7 +1617,7 @@ function form_test_two_instances() {
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => 'page',
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
);
$node2 = clone($node1);
$return['node_form_1'] = drupal_get_form('page_node_form', $node1);
......
......@@ -512,11 +512,11 @@
))
->values(array(
'name' => 'language_content_type_article',
'value' => 's:1:"1";',
'value' => 's:1:"2";',
))
->execute();
// Enable the locale module.
// Enable Locale and Translation module.
db_update('system')->fields(array(
'status' => 1,
'schema_version' => '7001',
......@@ -524,8 +524,20 @@
->condition('type', 'module')
->condition('name', 'locale')
->execute();
db_update('system')->fields(array(
'status' => 1,
'schema_version' => '7001',
))
->condition('type', 'module')
->condition('name', 'translation')
->execute();
// Add a sample node to test comments on.
// Add sample nodes to test language assignment and translation functionality.
// The first node is also used for testing comment language functionality. This
// is a simple node with LANGUAGE_NONE as language code. The second node is a
// Catalan node (language code 'ca'). The third and fourth node are a
// translation set with an English source translation (language code 'en') and a
// Chuvash translation (language code 'cv').
db_insert('node')->fields(array(
'nid',
'vid',
......@@ -558,9 +570,57 @@
'tnid' => '0',
'translate' => '0',
))
->values(array(
'nid' => '39',
'vid' => '55',
'type' => 'article',
'language' => 'ca',
'title' => 'Node title 39',
'uid' => '6',
'status' => '1',
'created' => '1263769300',
'changed' => '1263769300',
'comment' => '0',
'promote' => '0',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
))
->values(array(
'nid' => '40',
'vid' => '60',
'type' => 'article',
'language' => 'en',
'title' => 'Node title 40',
'uid' => '6',
'status' => '1',
'created' => '1263769534',
'changed' => '1263769534',
'comment' => '0',
'promote' => '0',
'sticky' => '0',
'tnid' => '40',
'translate' => '0',
))
->values(array(
'nid' => '41',
'vid' => '65',
'type' => 'article',
'language' => 'cv',
'title' => 'Node title 41',
'uid' => '6',
'status' => '1',
'created' => '1263770064',
'changed' => '1263770064',
'comment' => '0',
'promote' => '0',
'sticky' => '0',
'tnid' => '40',
'translate' => '0',
))
->execute();
// Add its node comment statistics.
// Add node comment statistics for the first node.
db_insert('node_comment_statistics')->fields(array(
'nid',
'cid',
......@@ -597,13 +657,49 @@
'vid' => '50',
'uid' => '6',
'title' => 'Node title 38',
'log' => 'added a node to comment on',
'log' => 'Added a LANGUAGE_NONE node to comment on.',
'timestamp' => '1314997642',
'status' => '1',
'comment' => '2',