diff --git a/i18n.install b/i18n.install index 0ad080d3f905908cb2c0e59e744a91d3e0a9d49e..636a55cd41b6047a060b426bb31af033e6f8b8bd 100644 --- a/i18n.install +++ b/i18n.install @@ -29,7 +29,9 @@ function i18n_install() { value longtext NOT NULL, PRIMARY KEY (name, language) )"); - + db_query("ALTER TABLE {menu} + ADD language VARCHAR(12) NOT NULL default '' + "); break; case 'pgsql': @@ -59,11 +61,17 @@ function i18n_install() { db_query("ALTER TABLE {vocabulary} ADD language varchar(12)"); db_query("UPDATE {vocabulary} SET language=''"); db_query("ALTER TABLE {vocabulary} ALTER COLUMN language SET NOT NULL"); - db_query("ALTER TABLE {vocabulary} ALTER COLUMN language SET DEFAULT ''"); - + db_query("ALTER TABLE {vocabulary} ALTER COLUMN language SET DEFAULT ''"); + + db_query("ALTER TABLE {menu} ADD language varchar(12)"); + db_query("UPDATE {menu} SET language=''"); + db_query("ALTER TABLE {menu} ALTER COLUMN language SET NOT NULL"); + db_query("ALTER TABLE {menu} ALTER COLUMN language SET DEFAULT ''"); + // Sequences db_query("CREATE SEQUENCE {i18n_node}_trid_seq INCREMENT 1 START 1"); db_query("CREATE SEQUENCE {term_data}_trid_seq INCREMENT 1 START 1"); + } } @@ -101,4 +109,14 @@ function i18n_update_4(){ )"); return $items; } + +/** + * Drupal 5 updates + */ +// Multilingual menu items +function i18n_update_5(){ + $items[] = update_sql("ALTER TABLE {menu} ADD language VARCHAR(12) NOT NULL default ''"); + return $items; +} + ?> \ No newline at end of file diff --git a/i18n.module b/i18n.module index 04ea0b62fbda1a839b4b33de7a742f5f90326273..d0f5d9d36ae3209128e3518ed81d5c43fa649383 100644 --- a/i18n.module +++ b/i18n.module @@ -106,11 +106,11 @@ function i18n_help($section = 'admin/help#i18n' ) { $output .= ''; $output .= '

'. t('For more information please read the on-line help pages.', array('@i18n' =>'http://drupal.org/node/31631')) .'

'; return $output; @@ -154,7 +154,7 @@ function i18n_menu($may_cache) { $language = $node->language; } if($language) i18n_selection_mode('node', db_escape_string($language)); - } elseif(arg(0) == 'admin') { + } elseif(arg(0) == 'admin' && user_access('administer all languages')) { // No restrictions for administration pages i18n_selection_mode('off'); } @@ -668,42 +668,28 @@ function i18n_db_rewrite_sql($query, $primary_table, $primary_key){ switch ($primary_table) { case 'n': case 'node': - // Node queries - return i18n_db_node_rewrite($query, $primary_table, $primary_key, $mode); + // Node queries. + // When loading specific nodes, language conditions shouldn't apply + if (preg_match("/WHERE.*\s$primary_table.nid\s*=\s*(\d|%d)/", $query)) return; + $result['join'] = "LEFT JOIN {i18n_node} i18n ON $primary_table.nid = i18n.nid"; + $result['where'] = i18n_db_rewrite_where('i18n', $mode); + return $result; case 't': case 'v': // Taxonomy queries - return i18n_db_taxonomy_rewrite($query, $primary_table, $primary_key, $mode); + // When loading specific terms, vocabs, language conditions shouldn't apply + if (preg_match("/WHERE.* $primary_table\.tid\s*(=\s*\d|IN)/", $query)) return; + // Taxonomy for specific node + if (preg_match("/WHERE r\.nid = \%d/", $query)) return; + $result['where'] = i18n_db_rewrite_where($primary_table, $mode); + return $result; + case 'm': + // Menu queries + $result['where'] = i18n_db_rewrite_where($primary_table, $mode); + return $result; } } -/** - * Rewrite node queries - */ -function i18n_db_node_rewrite($query, $primary_table, $primary_key, $mode){ - // When loading specific nodes, language conditions shouldn't apply - if (preg_match("/WHERE.*\s$primary_table.nid\s*=\s*(\d|%d)/", $query)) return; - - $result['join'] = "LEFT JOIN {i18n_node} i18n ON $primary_table.nid = i18n.nid"; - $result['where'] = i18n_db_rewrite_where('i18n', $mode); - - return $result; -} - -/** - * Rewrite taxonomy queries - */ -function i18n_db_taxonomy_rewrite($query, $primary_table, $primary_key, $mode){ - // When loading specific terms, vocabs, language conditions shouldn't apply - if (preg_match("/WHERE.* $primary_table\.tid\s*(=\s*\d|IN)/", $query)) return; - // Taxonomy for specific node - if (preg_match("/WHERE r\.nid = \%d/", $query)) return; - - $result['where'] = i18n_db_rewrite_where($primary_table, $mode); - - return $result; -} - /** * Rewrites queries depending on rewriting mode */ @@ -738,7 +724,7 @@ function i18n_exit(){ * This is the place to add language fields to all forms */ function i18n_form_alter($form_id, &$form) { - //drupal_set_message("i18n_form_alter form_id=$form_id "); + //drupal_set_message("DEBUG: i18n_form_alter form_id=$form_id "); switch($form_id){ case 'taxonomy_overview_vocabularies': $vocabularies = taxonomy_get_vocabularies(); @@ -795,7 +781,15 @@ function i18n_form_alter($form_id, &$form) { } $form['#submit'] = array('i18n_admin_manage_screen_submit' => array()) + $form['#submit']; break; - + case 'menu_edit_item_form': + if ($mid = $form['mid']['#value']) { + $language = db_result(db_query('SELECT language FROM {menu} WHERE mid = %d', $mid)); + } else { + $language = ''; + } + $form['language'] = _i18n_language_select($language, t('You can set a language for this menu item.')); + $form['#submit'] = array('i18n_menu_edit_item_form_submit' => array()); + break; default: // Node edit form if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { @@ -827,6 +821,27 @@ function i18n_form_alter($form_id, &$form) { } } +/** + * Implementation of hook_perm(). + * + * Permissions defined + * - administer all languages + * Disables language conditions for administration pages, so the user can view objects for all languages at the same time. + * This applies for: menu items, taxonomy + */ +function i18n_perm() { + return array('administer all languages'); +} +/** + * Process menu and menu item add/edit form submissions. + */ +function i18n_menu_edit_item_form_submit($form_id, $form_values) { + $mid = menu_edit_item_save($form_values); + drupal_set_message("Saving item $mid with language =". $form_values['language']); + db_query("UPDATE {menu} SET language = '%s' WHERE mid = %d", $form_values['language'], $mid); + return 'admin/build/menu'; +} + /** * Theme the locale admin manager form. */ diff --git a/translation/translation.module b/translation/translation.module index 6a8760fb4e0d54ffc1c9174dfe29f6cd7a71a933..d81950f1755ba6f703c340bbfcb46bdfcffa46ce 100644 --- a/translation/translation.module +++ b/translation/translation.module @@ -24,12 +24,18 @@ function translation_help($section = 'admin/help#translation' ) { switch ($section) { case 'admin/help#translation' : $output = '

'.t('This module is part of i18n package and provides support for translation relationships.').'

'; - $output = '

'.t('The objects you can define translation relationships for are:').'

'; + $output .= '

'.t('The objects you can define translation relationships for are:').'

'; $output .= ''; - $output .= '

'. t('For more information please read the on-line help pages.', array('@i18n' =>'http://drupal.org/node/31631')) .'

'; + $output .= '

'.t('Additional features:').'

'; + $output .= ''; + $output .= '

'.t('For more information please read the on-line help pages.', array('@i18n' =>'http://drupal.org/node/31631')) .'

'; return $output; break; case 'admin/access#translation':