Hi all,

I have some nodes with only the body field translatable.
My website have to show all nodes regardless the current language, in this way:

  1. If a node is translated: show the translated node for current language
  2. If a node is untranslated: show the source node, but with the localized url path
  3. If a node is language neutral: show the node with the localized url path

Now, I created a View of teaser, without any language filter: all works quite fine, in this way:
Suppose current language is ENGLISH:

  1. for case 1: ok, node (whose source lang is english and has a ita translation) is shown with path: mysite/en/node-1-alias
  2. for case 2: ok, node (whose source lang is english and doesn't have a ita translation) is shown with path: mysite/en/node-2-alias
  3. for case 3: ok, node (whose source lang is neutral) is shown with path: mysite/en/node-3-alias

Suppose current language is ITALIAN:

  1. for case 1: ok, node (whose source lang is english and has a ita translation) is shown with path: mysite/it/node-1-alias
  2. for case 2: mmmm, node (whose source lang is english and doesn't have a ita translation) is shown with path: mysite/it/node/[nid]
  3. for case 3: ok, node (whose source lang is neutral) is shown with path: mysite/it/node-3-alias

So, to better resolve last point 2, I'm asking if there is a way on node source creation (e.g. ENG) to anyway automatically create the path for untraslated content (-> ITA). In this way my untranslated content is visible with a consistent alias than the default "node/[nid]".

Alternatively, to reach the same result, please tell me the way (if exists) to automatically create the translation on a node (source) creation.

Thank you very much for helping me.

Comments

plach’s picture

Status: Active » Fixed

I am afraid there is no solution here that does not involve writing code. As you are rightly pointing out you need to:

mxt’s picture

Thank you for your answer, I'm actually trying to follow the first way: create a path alias for all languages when creating a node.

So here's what I did:

function helper_node_insert($node) {
  // @todo Remove the next line when http://drupal.org/node/1025870 is fixed.
  unset($node->uri);
  _helper_manage_alias_for_untraslated_nodes($node, 'insert');
}

function helper_node_update($node) {
  _helper_manage_alias_for_untraslated_nodes($node, 'update');
}

function _helper_manage_alias_for_untraslated_nodes($node, $op) {
  // Retrieve all languages already translated for this node:
  $existing_translations = $node->translations->data;

  // Retrieve all active languages in the site:
  $available_languages = language_list();

  // Diff between the above arrays: the results is a list of languages not yet translated:
  $pending_translations = array_diff_key($available_languages, $existing_translations);

  module_load_include('inc', 'pathauto');
  $uri = entity_uri('node', $node);

  if( !empty($pending_translations) ) {
    // add the alias for the untraslated languages:
    foreach( $pending_translations as $pending_translation ) {
      pathauto_create_alias('node', $op, $uri['path'], array('node' => $node), $node->type, $pending_translation->language);
    }
  }
}

The code seems to works nice, please tell me if it's a good stuff or there are better ways to proceed.

The only thing I haven't resolved yet is deletion management: we have 2 cases here:

  1. The SOURCE node is deleted -> all alias have to be deleted (this already works by default)
  2. A translations is deleted -> its alias have to be kept

To resolve point 2 I've tried:

function helper_node_delete($node) {
  // Only act on a translation, not a source:
  if ( $node->translations->original != $node->language ) {
    _helper_manage_alias_for_untraslated_nodes($node, 'insert');
  }
}

or:

function helper_entity_translation_delete($entity_type, $entity, $langcode) {
  module_load_include('inc', 'pathauto');
  $uri = entity_uri($entity_type, $entity);
  pathauto_create_alias('node', 'insert', $uri['path'], array('node' => $entity), $entity->type, $langcode);
}

But both doesn't work: alias of deleted translation is deleted too.

Any suggestion?

Thank you very much

plach’s picture

See entity_translation_delete_confirm_submit(): you need a submit handler acting after it (pretty bad code there: we should implement the delete hook on behalf of path now that we have it).

bforchhammer’s picture

See entity_translation_delete_confirm_submit(): you need a submit handler acting after it (pretty bad code there: we should implement the delete hook on behalf of path now that we have it).

#1865176: Implement hook_entity_translation_delete() on behalf of path module

barami’s picture

I found the clean solution. http://drupal.org/node/1126548#comment-6509484
i think following instructions.

First, When created node, if drupal creates path by pathauto, it makes a only one path with selected language.
(if you posted node with english, only english path exists.)
I think if we make paths both und language path and source language path by pathauto, drupal will use source language path to indicate source language, and another languages will be indicated by und language path as fallback.

Now, entity_translation module only implements entity_translation_pathauto_alias_alter function for bulk update. (See hook_pathauto_alias_alter)
So.. We must modify that function to create path on node creation.

mxt’s picture

@barami: this is very interesting: thank you very much!

I already thought to create a "parallel" language neutral path in any case, but abandoned the idea because I was not sure if this might have some kind of consequence in path/node management. Another reason is that different tokens for different path languages can't works with a unique UND path (with my partial solution above you can setup pathauto patterns with different tokens for every language).

But reading the link you have suggested (and the derivated ones) seems it could be a reasonable solution.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Small mistake