summaryrefslogtreecommitdiff
path: root/modules/translation/translation.module
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-17 04:22:50 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-17 04:22:50 +0000
commit917a37fb7e6f8ef522267d004a7ee365dd2cc23e (patch)
tree222e849285108e0f8045cd8064520a5e51a985cb /modules/translation/translation.module
parent269de32e8ae5e9175a476e050fdc1f11f1b9f6b7 (diff)
downloadbrdo-917a37fb7e6f8ef522267d004a7ee365dd2cc23e.tar.gz
brdo-917a37fb7e6f8ef522267d004a7ee365dd2cc23e.tar.bz2
#356136 by nedjo, catch, and stella: Prevent duplicate translations (with tests).
Diffstat (limited to 'modules/translation/translation.module')
-rw-r--r--modules/translation/translation.module28
1 files changed, 27 insertions, 1 deletions
diff --git a/modules/translation/translation.module b/modules/translation/translation.module
index 10a2eb1d1..9f3f0c569 100644
--- a/modules/translation/translation.module
+++ b/modules/translation/translation.module
@@ -200,8 +200,18 @@ function translation_node_prepare($node) {
(user_access('translate content'))) {
// We are translating a node from a source node, so
// load the node to be translated and populate fields.
+ $source_node = node_load($source_nid);
+ // Ensure we don't have an existing translation in this language.
+ if (!empty($source_node->tnid)) {
+ $translations = translation_node_get_translations($source_node->tnid);
+ if (isset($translations[$language])) {
+ $languages = language_list();
+ drupal_set_message(t('A translation of %title in %language already exists, a new %type will be created instead of a translation.', array('%title' => $source_node->title, '%language' => $languages[$language]->name, '%type' => $node->type)), 'error');
+ return;
+ }
+ }
$node->language = $language;
- $node->translation_source = node_load($source_nid);
+ $node->translation_source = $source_node;
$node->title = $node->translation_source->title;
$node->body = $node->translation_source->body;
// Let every module add custom translated fields.
@@ -249,6 +259,22 @@ function translation_node_update($node) {
}
/**
+ * Implementation of hook_node_validate().
+ *
+ * Ensure that duplicate translations can not be created for the same source.
+ */
+function translation_node_validate($node, $form) {
+ // Only act on translatable nodes with a tnid or translation_source.
+ if (translation_supported_type($node->type) && (!empty($node->tnid) || !empty($form['#node']->translation_source->nid))) {
+ $tnid = !empty($node->tnid) ? $node->tnid : $form['#node']->translation_source->nid;
+ $translations = translation_node_get_translations($tnid);
+ if (isset($translations[$node->language]) && $translations[$node->language]->nid != $node->nid ) {
+ form_set_error('language', t('There is already a translation in this language.'));
+ }
+ }
+}
+
+/**
* Implementation of hook_node_delete().
*/
function translation_node_delete($node) {