'es', 'name' => 'Spanish'); $items_per_run = 10; // arbitrary number - adjust to fit your needs // Get untranslated English wiki and document nodes up to $items_per_run $result = db_query_range("SELECT nid FROM {node} WHERE (type = 'book' OR type = 'page') AND language = 'en' AND tnid = 0 ORDER BY nid ASC", 0, $items_per_run); while ($row = db_fetch_array($result)) { // Iterate through the nodes // Load node and clear node cache afterward (necessary for performance on bulk operations). $src_node = node_load($row['nid'], NULL, TRUE); // Set node basics $node = array('type' => 'book', // type is wiki page 'pathauto_perform_alias' => 1, // make an alias ); $form_state = array(); // form_state is needed for drupal_execute // Use Translation Framework to translate the node title if(isset($src_node->title)) { $func = 'translation_framework_translate_send'; if (function_exists($func)) { $trans_title = call_user_func($func, $src_node->title, 'en', 'es'); $form_state['values']['title'] = $trans_title; } else { // If no Translation Framework, this process cannot work - end the loop watchdog('auto_translate', 'Translation Framework not available.', array(), WATCHDOG_ERROR); break; } } else { // If no title, proceed to the next node watchdog('auto_translate', 'No title for %src_node, skipping translation', array('%src_node' => $row['nid']), WATCHDOG_NOTICE); continue; } // Tell i18n and Translation Framework that we are making a translation of the source node $_GET['language'] = 'es'; $_GET['translation'] = $src_node->nid; $form_state['values']['language'] = 'es'; $form_state['values']['translation_source'] = $src_node; // Add settings needed to create the node $form_state['values']['is_new'] = TRUE; // New node $form_state['values']['status'] = 1; // Published $form_state['values']['format'] = 5; // Unfiltered HTML - otherwise will break b/c of high-memory HTML filters $form_state['values']['op'] = t('Save'); // Save it! //kprint_r($form_state); //Programmatically submit this to the wiki form drupal_execute('book_node_form', $form_state, (object)$node); if(isset($form_state['nid'])) { // get terms for the original node & save them also $dst_node = node_load($form_state['nid'], NULL, TRUE); $terms = taxonomy_node_get_terms($src_node); taxonomy_node_save($dst_node, $terms); watchdog('auto_translate', 'Created %lang translation of %src_node named %dst_node', array('%lang' => $dst_lang['name'], '%src_node' => $src_node->title . '(' . $src_node->nid . ')', '%dst_node' => $dst_node->title . '(' . $dst_node->nid . ')'), WATCHDOG_NOTICE); } else { watchdog('auto_translate', 'Translation of %src_node failed', array('%src_node' => $src_node->title . '(' . $src_node->nid . ')'), WATCHDOG_ERROR); } } }