Implement i18n menu support

ArjanLikesDrupal - September 27, 2008 - 15:47
Project:Menu Trails
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I have installed Menutrail on a multilingual site running on three domains, one for each language. Each language has another primary links menu. The settings are saved separately using this in my settings.php: (after this tip here http://drupal.org/node/165527#comment-870834).

$conf['i18n_variables'] = array(
  'menutrails_menu',
  'menutrails_node_types',
  'menutrails_terms',
);

Now everything works great, it even works for the Biblio node-type (from Biblio module. BUT, for some reason it only works on one of the menus, the English one. On the other two domains, using different primary menus, only for the Biblio type the correct parent menu will not be set. I've spent hours reading about and trying all kinds of tricks, no luck. But since it works for one language/menu with Menutrails, any suggestions to make it work?

#1

joshk - October 13, 2008 - 21:37
Title:Menutrails works for biblio node-type in one menu, but not the other - howto fix?» Implement i18n menu support
Category:support request» feature request

I'm willing to bet there is additional code needed to support internationalization. This will need some further research to figure out. Thanks for bringing this to my attention!

#2

ArjanLikesDrupal - October 13, 2008 - 22:18

Cool, I'll be available for testing when there are new developments.

#3

joshk - October 14, 2008 - 00:01

Excellent. I saw all the code in the other thread here:

http://drupal.org/node/165527

It'll probably be some days before I really have time to dig into it, but i18n is an important feature (esp for Drupal 6) and I want to support it.

#4

sharlak - March 9, 2009 - 12:37

I added 'menutrails_menu', 'menutrails_node_types' and 'menutrails_terms' to 'i18n_variables' in my settings.php as it has been said here and tested it. For the moment everything seems to work fine. I have created a menu for my Spanish content (called Test-es) and another one for its translation to Basque (called Test-eu). After configuring menu trails module in both languages I got the active-trail class in the defined parent items as I expected (using both nodetypes and taxonomy configuration), so I think that this solves the issue.

I'm using Internationalization 6.x-1.0 and Menu Trails 6.x-1.0. Can anyone give more feedback?

#5

tibbsa - July 23, 2009 - 20:24

I have tried, unsuccessfully, to use Menu Trails on a new bilingual (French/English) D6 site. I added the menutrails_* variables to the i18n_variables list in settings.php (as I have done for numerous other modules, so I know this 'works'), and this did indeed allow me to configure separate English & French assignments in the UI.

On this site, two site-specific menus are used (i.e. not Primary or Secondary links) - one for English and one for French.

Associating by node type or taxonomy works great for the primary language (English), and results in appropriate breadcrumbs and "active" item indication.

It does not appear to be doing anything at all when operating in French, however.

Is there anywhere or anything else I could check?

#6

domidc - August 13, 2009 - 12:45

Set the multilingual variables. If you have urls going to the same path in both languages like a view that has a language filter for example, you need to hack the module a little.
To the owner of this module: proper i18n support would be nicer, but for now this fix works fine for me.

Change this function :

function _menutrails_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {
  foreach ($tree as $data) {
    if ($data['link']['depth'] > $depth_limit) {
      // Don't iterate through any links on this level.
      break;
    }
    if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) {
      $title = $indent .' '. truncate_utf8($data['link']['title'], 30, TRUE, FALSE);
      if (!$data['link']['hidden']) {
        $options[$data['link']['href']] = $title;
      }
      if ($data['below']) {
        _menutrails_parents_recurse($data['below'], $menu_name, $indent .'--', $options, $exclude, $depth_limit);
      }
    }
  }
}

Into:

function _menutrails_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {
  foreach ($tree as $data) {
    if ($data['link']['depth'] > $depth_limit) {
      // Don't iterate through any links on this level.
      break;
    }
    if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) {
      $title = $indent .' '. truncate_utf8($data['link']['title'], 30, TRUE, FALSE);
      if (!$data['link']['hidden']) {
        if (module_exists('i18n')) {
          if (i18n_get_lang() == $data['link']['localized_options']['langcode']) {
            $options[$data['link']['href']] = $title;
          }
        }
        else {
        $options[$data['link']['href']] = $title;
        }
      }
      if ($data['below']) {
        _menutrails_parents_recurse($data['below'], $menu_name, $indent .'--', $options, $exclude, $depth_limit);
      }
    }
  }
}

#7

marcushenningsen - October 7, 2009 - 22:23

I can confirm that entering the above mentioned lines of code into settings.php works perfectly. This, however, seems like a workaround. Should this somehow be entered into the module itself?

#8

DomoSapiens - December 2, 2009 - 14:42

I have the same problem, but adding the 'i18n_variables' did the trick for me.
It works great! Thanks

 
 

Drupal is a registered trademark of Dries Buytaert.