3

I use Drupal 7, entity_translation and pathauto with 2 languages: EN, FR.

I create a new content (of a content type with "entity translation") and I title it "test". Since Generate automatic URL alias is enabled, the URL /test displays the content.

I then translate this to French and submit.

On the sidebar I have a language selector which for FR links to /fr/node/1.

How is it possible to automatically make it link to /fr/test? The only way to solve this is by manually typing test in the alias of the French translated content. Why isn't pathauto working in the translations of the node?

  • There is a lot of movement around ET these days. This thread gives you an idea. My advice : search the ET issue queue and brew your own stuff with the various patches. Don't forget to look at the D8 issues, as work goes here first, then things will eventually get backported to D7. – Countzero Apr 23 '12 at 17:16
3

Entity Translation 7.x-1.x-dev solves this.

Hint provided in the Packt Drupal-7-Multilingual-Sites book:

Pathauto works fine for nodes using the node translation model as each language has a separate node. At the time of writing, for feld translation, the Pathauto and Entity Translation module maintainers have been ironing out some issues. To get the automatic URL aliases to work in Drupal 7 for feld-translated nodes, you must use at least Entity Translation version 7.x-1.0-alpha2, if available, or the most recent dev version.

3

Latest dev version of entity translation didn't change anything so we solved it by changing line 1959 in entity_translation.module

if ($context['op'] == 'bulkupdate' && !empty($info[$entity_type]['token type']) && !empty($context['data'][$info[$entity_type]['token type']])) {

to

if (($context['op'] == 'update' || $context['op'] == 'bulkupdate') && !empty($info[$entity_type]['token type']) && !empty($context['data'][$info[$entity_type]['token type']])) {

This way pathauto_create_alias() is fired also when updating/creating content.

2

You can use the Synchronize Translation Paths module.

Without it, URL path aliases are not synchronized across translations. When translations are saved, the URL path alias is assigned to the corresponding language, thereby eliminating any language-neutral aliases in the database. So if you surf to a different language, there won't be any alias set unless you go and add them from the UI or DB client.

0

Entity Translation 7.x-1.x-dev does not solve this for me.

I had to implement next hooks as a workaround:

/**
 * Implements hook_url_inbound_alter().
 *
 * Resolves alias if the content is not translated.
 */
function MYMODULE_url_inbound_alter(&$path, $original_path, $path_language) {
  // Check if no url alias has not been found for incoming path.
  if ($path && $path == $original_path) {
    // Resolve alias if the content is not translated to current language. Get
    // alias of existing translation.
    foreach (array_keys(language_list()) as $language) {
      if ($source = drupal_lookup_path('source', $path, $language)) {
        // Check if we are at the document page.
        if (strpos($source, 'node/') === 0) {
          $path = $source;
          break;
        }
      }
    }
  }
}

/**
 * Implements hook_url_outbound_alter().
 *
 * Resolves alias from node language if the content is not translated.
 */
function MYMODULE_url_outbound_alter(&$path, &$options, $original_path) {
  if (preg_match('/^node\/\d+$/', $path) && $node = menu_get_object('node', 1, $path)) {
    if ($alias = drupal_get_path_alias($path, $node->language)) {
      $path = $alias;
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.