function translation_node_prepare in Internationalization 5.3
Same name and namespace in other branches
- 5 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 376
Code
function translation_node_prepare(&$node, $sourcenid, $language) {
// Validate source and language.
$source = node_load($sourcenid);
if (empty($source) || !translation_access($source) || !node_access('view', $source)) {
// Source node not found or no access to view.
return;
}
$language_list = i18n_node_language_list($node);
if (!isset($language_list[$language]) || $source->language == $language) {
// If not supported language, or same language as source node, break.
return;
}
$node->translation_source = drupal_clone($source);
$node->translation_nid = $sourcenid;
$node->language = $language;
// 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;
// Only copy the body if the translator can access the format.
if (filter_access($source->format)) {
$node->body = $source->body;
}
// Rest of fields. Unset some known ones not to be copied over
unset($source->nid, $source->vid, $source->path, $source->language, $source->files, $source->body);
foreach ($source as $field => $value) {
if (!isset($node->{$field})) {
$node->{$field} = $value;
}
}
}