function translation_node_prepare in Internationalization 5
Same name and namespace in other branches
- 5.3 translation/translation.module \translation_node_prepare()
- 5.2 translation/translation.module \translation_node_prepare()
Prepare node for translation
1 call to translation_node_prepare()
- translation_nodeapi in translation/
translation.module - Implementation of hook_nodeapi().
File
- translation/
translation.module, line 366
Code
function translation_node_prepare(&$node, $sourcenid, $language) {
$node->translation_nid = $sourcenid;
$node->language = $language;
$source = $node->translation_source = node_load($node->translation_nid);
// Taxonomy translation
if (is_array($source->taxonomy)) {
// Set translated taxonomy terms
$node->taxonomy = array();
foreach ($source->taxonomy as $tid => $term) {
if ($term->language) {
$translated_terms = translation_term_get_translations(array(
'tid' => $tid,
));
if ($translated_terms && ($newterm = $translated_terms[$node->language])) {
$node->taxonomy[$newterm->tid] = $newterm;
//drupal_set_message("DEBUG: Translated term $tid to ". $newterm->tid);
}
}
else {
// Term has no language. Should be ok
$node->taxonomy[$tid] = $term;
}
}
}
// Book outlines, translating parent page if exists
if ($source->parent && ($translations = translation_node_get_translations(array(
'nid' => $source->parent,
))) && isset($translations[$language])) {
$node->parent = $translations[$language]->nid;
}
// Translations are taken from source node
$node->translation = $source->translation;
$node->translation[$source->language] = $source;
// Rest of fields. Unset some known ones not to be copied over
unset($source->nid, $source->vid, $source->path, $source->language, $source->files);
foreach ($source as $field => $value) {
if (!isset($node->{$field})) {
$node->{$field} = $value;
}
}
}