Index: /drupal/modules/simple_translation/trunk/TODO =================================================================== --- /drupal/modules/simple_translation/trunk/TODO (revision 11) +++ /drupal/modules/simple_translation/trunk/TODO (revision 30) @@ -0,0 +1,2 @@ +- Translation of CCK text fields +- Translated attachments if they exist Index: /drupal/modules/simple_translation/trunk/patches/notes =================================================================== --- /drupal/modules/simple_translation/trunk/patches/notes (revision 30) +++ /drupal/modules/simple_translation/trunk/patches/notes (revision 30) @@ -0,0 +1,4 @@ +line 1017 menu.inc +// Nick: $new_tree[(50000 + $item['weight']) .' '. $item['title'] .' '. $item['mlid']] = $tree[$key]; + // Nick: take title out of the equation. + $new_tree[(50000 + $item['weight']) .' '. $item['mlid']] = $tree[$key]; Index: /drupal/modules/simple_translation/trunk/patches/menu.inc.drupal-6.5.tree-item-hook.patch =================================================================== --- /drupal/modules/simple_translation/trunk/patches/menu.inc.drupal-6.5.tree-item-hook.patch (revision 11) +++ /drupal/modules/simple_translation/trunk/patches/menu.inc.drupal-6.5.tree-item-hook.patch (revision 30) @@ -6,5 +6,5 @@ while ($item = db_fetch_array($result)) { + -+ // This hook allows modules to modify menu items before rendering. ++ // Nick Blundell 2008: This hook allows modules to modify menu items before rendering. + foreach (module_implements('menu_tree_item_alter') as $name) { + $function = $name .'_menu_tree_item_alter'; Index: /drupal/modules/simple_translation/trunk/simple_translation.module =================================================================== --- /drupal/modules/simple_translation/trunk/simple_translation.module (revision 11) +++ /drupal/modules/simple_translation/trunk/simple_translation.module (revision 30) @@ -9,4 +9,8 @@ if (!function_exists("d")) { function d($message, $item=null, $print=false) { + global $user; + if ($user->uid != 1) { + return; + } if ($item) { $message .= ": " . print_r($item,true); @@ -29,5 +33,8 @@ function simple_translation_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { - + // Don't translate when we are editing a node. + if (dont_translate()) { + return; + } global $language; @@ -37,5 +44,5 @@ return; } - + // Load the translation source node. $sNode = safe_node_load($node->tnid); @@ -56,4 +63,5 @@ // Replace the loaded node with the translated node. //$node = $tNode; + //d("source node: $node->nid - trans node: $tNode->nid"); $node->title = $tNode->title; $node->body = $tNode->body; @@ -80,5 +88,7 @@ // Replace the menu title with the translated title. // Remember, we hook node_load in this module to translate it. + // TODO: Would be more efficient to make a DB call to get title rather than node_load $node = node_load($nid); + //d("Translating title ".$item["link_title"]. " to trans node title $node->title"); $item["link_title"] = $node->title; return; @@ -93,4 +103,7 @@ function simple_translation_db_rewrite_sql($query, $primary_table, $primary_key, $args = array()){ // Adapted from i18n module + + // Contrary to i18n, only act on views queries, so we don't break other system queries. + if (!array_key_exists('view',$args)) return; $query_mods = array(); @@ -112,7 +125,7 @@ // Show only translation sources from translation sets. - $query_mods["where"] = "$primary_table.nid = $primary_table.tnid OR $primary_table.language = ''"; - } - + $query_mods["where"] = "$primary_table.tnid = 0 OR $primary_table.nid = $primary_table.tnid OR $primary_table.language = ''"; + } + //d("query_mods", $query_mods); return $query_mods; } @@ -120,5 +133,4 @@ function simple_translation_views_pre_render(&$view) { - //d("result",$view->result); foreach ($view->result as $item) { if (!$item->nid) { continue; } @@ -141,5 +153,5 @@ /* Initialise the module. */ function simple_translation_init() { - + // Need to clear the menu cache to allow menu translation. // TODO: Need to find a better way. @@ -155,4 +167,14 @@ * ======================================= */ + + +function dont_translate() { + $path = $_GET['q']; + + if (stristr($path, "/translate")) { return true; } + if (stristr($path, "/edit")) { return true; } + //d($path); + return false; +} /* Loads a node in such a way that it will not be processed recursively by our nodeapi hook. */ @@ -168,5 +190,7 @@ /* Loads the translated version of a node or returns the original node if no translation. */ function _load_translated_node(&$node, $language) { - + + //return $node; + // Return original if no trans source, non-lang specific node, or the node language is same as user language. if (!($node->tnid and $language->language) or $language->language == $node->language) { @@ -187,63 +211,3 @@ -/* - * ======================================= - * OLD STUFF - * ======================================= - */ - -function xxxsimple_translation_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { - // TODO: When incomming node is a translated node, comments of trans source are not dispayed. - - global $language; - - if ($op != "alter") { - return; - } - - // State what the arguments are. - $teaser = $a3; - $page = $a4; - - // Get the translation source node of this node - $sNode = node_load($node->tnid); - - if (!$sNode) { - return; - } - - // Get the translated node. - $tNode = _load_translated_node($sNode, $language); - - if (!$tNode) { - return; - } - - // Sadly need to re-build the node's content, since drupal_render cannot be called more than once on content. - $sNode = node_build_content($sNode, $teaser, $page); - - // Render the node and update the originally rendered node. - $tNode = node_build_content($tNode, $teaser, $page); - - // Render the content in the correct language. - $sNode->content["body"] = $tNode->content["body"]; - $renderedContent = drupal_render($sNode->content); - $sNode->teaser = $renderedContent; - $sNode->body = $renderedContent; - - // Update the page title. - $sNode->title = $tNode->title; - drupal_set_title(check_plain($sNode->title)); - - // Update the links - $sNode->links = module_invoke_all('link', 'node', $tNode, $teaser); - drupal_alter('link', $sNode->links, $tNode); - - // Replace $node with the modified $sNode - $node = $sNode; -} - - - - ?>