Changeset 30
- Timestamp:
- 02/21/09 20:26:24 (2 years ago)
- Files:
-
- drupal/modules/simple_translation/trunk/TODO (modified) (1 diff)
- drupal/modules/simple_translation/trunk/patches/menu.inc.drupal-6.5.tree-item-hook.patch (modified) (1 diff)
- drupal/modules/simple_translation/trunk/patches/notes (added)
- drupal/modules/simple_translation/trunk/simple_translation.module (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
drupal/modules/simple_translation/trunk/TODO
r11 r30 1 - Translation of CCK text fields 2 - Translated attachments if they exist drupal/modules/simple_translation/trunk/patches/menu.inc.drupal-6.5.tree-item-hook.patch
r11 r30 6 6 while ($item = db_fetch_array($result)) { 7 7 + 8 + // This hook allows modules to modify menu items before rendering.8 + // Nick Blundell 2008: This hook allows modules to modify menu items before rendering. 9 9 + foreach (module_implements('menu_tree_item_alter') as $name) { 10 10 + $function = $name .'_menu_tree_item_alter'; drupal/modules/simple_translation/trunk/simple_translation.module
r11 r30 9 9 if (!function_exists("d")) { 10 10 function d($message, $item=null, $print=false) { 11 global $user; 12 if ($user->uid != 1) { 13 return; 14 } 11 15 if ($item) { 12 16 $message .= ": " . print_r($item,true); … … 29 33 30 34 function simple_translation_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { 31 35 // Don't translate when we are editing a node. 36 if (dont_translate()) { 37 return; 38 } 32 39 33 40 global $language; … … 37 44 return; 38 45 } 39 46 40 47 // Load the translation source node. 41 48 $sNode = safe_node_load($node->tnid); … … 56 63 // Replace the loaded node with the translated node. 57 64 //$node = $tNode; 65 //d("source node: $node->nid - trans node: $tNode->nid"); 58 66 $node->title = $tNode->title; 59 67 $node->body = $tNode->body; … … 80 88 // Replace the menu title with the translated title. 81 89 // Remember, we hook node_load in this module to translate it. 90 // TODO: Would be more efficient to make a DB call to get title rather than node_load 82 91 $node = node_load($nid); 92 //d("Translating title ".$item["link_title"]. " to trans node title $node->title"); 83 93 $item["link_title"] = $node->title; 84 94 return; … … 93 103 function simple_translation_db_rewrite_sql($query, $primary_table, $primary_key, $args = array()){ 94 104 // Adapted from i18n module 105 106 // Contrary to i18n, only act on views queries, so we don't break other system queries. 107 if (!array_key_exists('view',$args)) return; 95 108 96 109 $query_mods = array(); … … 112 125 113 126 // Show only translation sources from translation sets. 114 $query_mods["where"] = "$primary_table. nid = $primary_table.tnid OR $primary_table.language = ''";115 } 116 127 $query_mods["where"] = "$primary_table.tnid = 0 OR $primary_table.nid = $primary_table.tnid OR $primary_table.language = ''"; 128 } 129 //d("query_mods", $query_mods); 117 130 return $query_mods; 118 131 } … … 120 133 121 134 function simple_translation_views_pre_render(&$view) { 122 //d("result",$view->result);123 135 foreach ($view->result as $item) { 124 136 if (!$item->nid) { continue; } … … 141 153 /* Initialise the module. */ 142 154 function simple_translation_init() { 143 155 144 156 // Need to clear the menu cache to allow menu translation. 145 157 // TODO: Need to find a better way. … … 155 167 * ======================================= 156 168 */ 169 170 171 function dont_translate() { 172 $path = $_GET['q']; 173 174 if (stristr($path, "/translate")) { return true; } 175 if (stristr($path, "/edit")) { return true; } 176 //d($path); 177 return false; 178 } 157 179 158 180 /* Loads a node in such a way that it will not be processed recursively by our nodeapi hook. */ … … 168 190 /* Loads the translated version of a node or returns the original node if no translation. */ 169 191 function _load_translated_node(&$node, $language) { 170 192 193 //return $node; 194 171 195 // Return original if no trans source, non-lang specific node, or the node language is same as user language. 172 196 if (!($node->tnid and $language->language) or $language->language == $node->language) { … … 187 211 188 212 189 /*190 * =======================================191 * OLD STUFF192 * =======================================193 */194 195 function xxxsimple_translation_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {196 // TODO: When incomming node is a translated node, comments of trans source are not dispayed.197 198 global $language;199 200 if ($op != "alter") {201 return;202 }203 204 // State what the arguments are.205 $teaser = $a3;206 $page = $a4;207 208 // Get the translation source node of this node209 $sNode = node_load($node->tnid);210 211 if (!$sNode) {212 return;213 }214 215 // Get the translated node.216 $tNode = _load_translated_node($sNode, $language);217 218 if (!$tNode) {219 return;220 }221 222 // Sadly need to re-build the node's content, since drupal_render cannot be called more than once on content.223 $sNode = node_build_content($sNode, $teaser, $page);224 225 // Render the node and update the originally rendered node.226 $tNode = node_build_content($tNode, $teaser, $page);227 228 // Render the content in the correct language.229 $sNode->content["body"] = $tNode->content["body"];230 $renderedContent = drupal_render($sNode->content);231 $sNode->teaser = $renderedContent;232 $sNode->body = $renderedContent;233 234 // Update the page title.235 $sNode->title = $tNode->title;236 drupal_set_title(check_plain($sNode->title));237 238 // Update the links239 $sNode->links = module_invoke_all('link', 'node', $tNode, $teaser);240 drupal_alter('link', $sNode->links, $tNode);241 242 // Replace $node with the modified $sNode243 $node = $sNode;244 }245 246 247 248 249 213 ?>
