We have the language element hidden for all editing operations for node content. When editing an English language node (English is the default language), clicking Translate, and then clicking a language link, like French, to add its translation, the hidden form language element is set to English because it pulls the language from the source entity in the getLanguage() method. When the element is hidden and the user is adding a non-English translation, the language element should be set to the destination language.

The primary issue we are having based on this problem is that every URL in url_alias for each translation of a node entity has the same language value, which is 'en'. So, we can translate node data, but then the URL alias for the non-English translations all still have the 'en' value. So, when you build a link to the node, the most recent url_alias record is retrieved, so you might see a French URL when browsing in English.

Basically, the language being saved in url_alias() is incorrect.

Note that I am fairly new to this module, so the actually error may be taking place elsewhere, when the translation data is saved, and I am still looking into that part.

CommentFileSizeAuthor
#2 path.patch685 bytesmaks9889
#2 entity_translation.patch1.18 KBmaks9889
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

justageek’s picture

Issue summary: View changes
maks9889’s picture

FileSize
1.18 KB
685 bytes

It happens because Entity translation uses field "language" for indicating "Original language" and function path_form_element_validate() in path.module changes form language to be equal to this field. I made little edit of these modules and attached patches for both.

PS. Aliases also have other multi-language issue and me write it little later.

Frando’s picture

I also ran into this bug. In my case, I got "The alias is already in use." validation errors, because path.module checked for uniqueness in the wrong language (original language instead of current translation), meaning that whenever the given alias exists already in the original language, but not in the current translation's language, path.module raised a wrong validation error because it picks up the wrong language.

Because I didn't want to patch core or entity_translation for this atm, I used the following code in a custom module as a workaround. It works perfectly well. The custom module needs a weight of at least 1 though to run after path module's form_alter.

/**
 * Implementation of hook_form_node_form_alter().
 *
 * This fixes a bug between path and entity_translation modules.
 * The path module's form validation tries to check that aliases are unique
 * among a language, but fails to pick up the translation language during
 * validation if using entity_translation. This is because entity_translation
 * changes the meaning of $form['language'] from "current language" to 
 * "original language".
 *
 * The following replaces path module's element validation with a custom one
 * that removes the language form value while calling path module's validation,
 * if editing a translation, making path module's validation pick up the 
 * corect language.
 */
function MYMODULE_form_node_form_alter(&$form, &$form_state, $form_id) {
  if (!empty($form['path']['#element_validate']) 
    && $form['path']['#element_validate'][0] == 'path_form_element_validate') {
    $form['path']['#element_validate'][0] = 'MYMODULE_path_form_element_validate';
  }
}


function MYMODULE_path_form_element_validate($element, &$form_state, $complete_form) {
  if (isset($form_state['values']['language']) 
    && !empty($complete_form['language']['#disabled'])
    && !empty($complete_form['language']['#multilingual'])) {

    $original_language = $form_state['values']['language'];
    unset($form_state['values']['language']);
  }
  path_form_element_validate($element, $form_state, $complete_form);
  if (!empty($original_language)) {
    $form_state['values']['language'] = $original_language;
  }
}
Ludo.R’s picture

I've used #3 solution and it seems to work very well!