Hello,

So this might be a bug, but I didn't want to be presumptuous.

I have a multilingual site that has a menu with translation configured as "Translate and Localize. Menu items with language will allow translations. Menu items without language will be localized"

The menu item of a particular node, is configured with a language (Russian), but the parent is configured as language neutral and I'm using the string translation function of Menu to translate the text of the parent menu item. So for a page node, there is an English Version and a Russian version. Two nodes (Content Translation) and two menu items. One parent, language neutral with a Russian version that pulls in fine on the site (via Menu Block).

I'm using a pathauto pattern of "[node:menu-link:parent]/[node:title]"
When I generate automatic alias for the Russian node, the text used for the parent menu-link is still in English.

I tried generating the alias with admin language set to both English and Russian. Same result.

I did some quick trace debugging and I do see that _token_menu_link_translate is calling _menu_item_localize, but the English (original) version of the parent menu-link title is still in place.

Any thoughts?

Comments

Bohus Ulrych’s picture

For anyone who is looking for solution I found this post which helped me https://drupal.org/node/1892442

I think is should be fixed in the token module.

Bohus Ulrych’s picture

Issue summary: View changes
Status: Active » Reviewed & tested by the community

This patch seems will fix this issue https://www.drupal.org/node/1892442#comment-8854323

gnucifer’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
9.78 KB

In my opinion this should be patched in the token module (or i18_menu, but that would be messier since there is no good entry point, so that all token would be have to generated once again probably with a lot of code duplication). Here is a patch that will fix the problem.

gnucifer’s picture

Somehow [node:menu-link:parents] is not translating correctly (it seems). I will try to fix this and update the patch.

gnucifer’s picture

Now it should work better, the problem was i18_menu setting the title value again through hook_tranlated_menu_link_alter, and by calling i18_menu_link_process in the token menu item processing we avoid this.

gnucifer’s picture

_i18n_menu_link_process skips node admin pages, so had to work around that. Now path generation works also on node edit forms.

suldan’s picture

Patch #6 fixed the issue on node admin pages and for bulk generated paths.

Thanks!

RAWDESK’s picture

I tried patch #6 to solve a similar issue with [node:menu-link:title] translation from within a metatag configuration, but it didn't seem to have any effect.
Apparently the menu items in our application are, beside localization, also translatable via a Translation set, supported by Entity Translation.

I've written the below hook_tokens_alter() to make both translation methods compatible for token translations.

function mymodule_tokens_alter(array &$replacements, array $context) {

    if (!array_key_exists('[node:menu-link:title]',$replacements) || !isset($context['data']['menu-link'])) {
        return;
    }

    global $language;
    $link = $context['data']['menu-link'];

    if (isset($link['i18n_tsid']) && function_exists('i18n_menu_translation_load')) {
      // translate via entity translation set if set available for this menu link
      $translation_set = i18n_menu_translation_load($link['i18n_tsid']);
      $translated_menu_item = $translation_set->get_item($language->language);
      $replacements['[node:menu-link:title]'] = $translated_menu_item['link_title'];

    } elseif (function_exists('_i18n_menu_link_title')) {
      // translate via i18n_menu localization
      $localized_link = _i18n_menu_link_title($link, $language->language);
      $replacements['[node:menu-link:title]'] = $localized_link;
    }
}

It looks an opportunity to me to extend patch #6 with this Translation Set support.
Shared ideas are welcome in this.

bwaindwain’s picture

patch #6 works great for me using [node:menu-link:parents] with token 7.x-1.6 with pathauto

RAWDESK’s picture

@bwaindwain,
Can you move status to "Reviewed and tested" so this gets merged into the next rc ?
Thanks.

bwaindwain’s picture

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

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

This definitely needs test coverage to confirm it works and won't regress in the future.

Pol’s picture

Patch #6 is working successfully, thanks!