This patch uses the hook hook_token_alter() to ensure that the translated value is used as replacement if applicable.
Review is definitely needed since I'm not sure this works really in every case.
The case the patch is written for is to integrate pathauto with entity_translation.

Would be great if someone comes up with an idea how to solve this without using this hook. ;)

Comments

das-peter’s picture

Related feature request in entity_translation module: #1155134: Integrate pathauto bulk generation

plach’s picture

The patch looks good apart from the minor issue below (I will fix it myself while committing it). I didn't actually tested it yet, hope to do it soon.

+++ title.module
@@ -467,3 +467,39 @@ function title_form_field_ui_field_overview_form_alter(&$form, &$form_state) {
+            if(!empty($item)) {

Missing space between the if keyword and the condition.

Powered by Dreditor.

dave reid’s picture

Status: Needs review » Needs work
+++ title.moduleundefined
@@ -467,3 +467,39 @@ function title_form_field_ui_field_overview_form_alter(&$form, &$form_state) {
+  if ($fr_info && $context['data'][$context['type']]) {

Should use !empty($context['data'][$context['type']]) here as it may not be defined and will throw a PHP notice.

Powered by Dreditor.

joostvdl’s picture

subscribe

calculus’s picture

subscribe

das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB

Just rerolled. Thanks @plach & @Dave Reid for the feedback.

renat’s picture

Patch from #6 works fine for me, see http://drupal.org/node/1155134#comment-4648088

plach’s picture

Status: Needs review » Reviewed & tested by the community
plach’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD.

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

stone_d’s picture

title-add-token-support.patch queued for re-testing.

The last submitted patch, title-add-token-support.patch, failed testing.

The last submitted patch, title-add-token-support.patch, failed testing.

  • Commit aeb07a9 on 7.x-1.x, workbench by plach:
    Issue #1155128 by das-peter | Dave Reid, plach: Enhanced support for...
lmeurs’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Hi,

On a multilangual website with the Internationalization, Entity translation, Title, Pathauto and Token modules installed it occurred to me that the title attributes of links in the language switchers were incorrect, so I started digging and noticed something else. I am not sure whether this is considered a bug or not, but I thought it was worth mentioning since it might cause other problems.

In short: when translating a localized term, Pathauto generates a path according to the default pattern for terms [term:vocabulary]/[term:name]. This triggers title_tokens_alter() which calls title_field_sync_get() which sets the term object's name and name_original properties. These changes to the entity object are done to find a replacement for the token, but are also used by code executed after title_tokens_alter() is done.

The effects are:

  1. After saving a translated term, an "Updated term [NAME_OF_TERM]." message should appear with the term's name in the source language, but it shows the translated name.
  2. Records are automatically created in database tables locales_source and locales_target for this taxonomy term. The source should be in the term's source language, but after saving a translation it's in the language of translation. (NB: I do not know why these records are created, since the target value is empty and translations are stored in their respective field tables)

Though these effects seem rather harmless, it might cause trouble at other levels as well.

Workaround: use the [term:vocabulary]/[term:name_field] pattern.

Possible solution: clone the term object before sending to title_field_sync_get():

title_field_sync_get($entity_type, $entity, $legacy_field, $info, $langcode);
item = $entity->{$legacy_field};

could become:

$cloned_entity = clone $entity;
title_field_sync_get($entity_type, $cloned_entity, $legacy_field, $info, $langcode);
$item = $cloned_entity->{$legacy_field};

Hope this makes any sense!

NB: I tested this on a clean install at simplytest.me with named modules and i18n's submodule Taxonomy translation enabled. I added a 2nd language, set the vocabulary's translation mode to "Localize" and replaced the original name field for this module's name field.

pol’s picture

Hi all,

Be aware that the committed patch in #6 might introduce security issue because the token values are not sanitized.

See this thread for more info: #2757739: Token value is not sanitized, when replaced from title field