First, this a great module to improve usability! So thanks a lot!

But, wouldn't it be great if menutrails could smoothly integrate i18n?

The current issue is in configure menutrails page, only showing current lannguage menu items. After switching language, any new modfication erase previuosly saved parameters !

Comments

jchatard’s picture

Well I just tried something that works for me. But what I've done so far, modify the way menutrails work!

In my case, the menutrails' configuration page isn't effective anymore. My snippet just search for the taxonomy term the node belongs to, and then search if a menu_item for this term exists ! If so, set location to this menu_item.

I have modified the menutrails_node_location this way :

// inspired by _menu_get_active_trail()
function menutrails_node_location($node) {
  // this should only fire if the menu isn't already active
  $item = menu_get_item(NULL, 'node/'.$node->nid);

  // type = 4 is for a callback
  if ($item['type'] == 4) {
    foreach($node->taxonomy as $tid => $term) {
      $result = db_result(db_query("SELECT mid FROM {menu} WHERE path = 'taxonomy/term/%s'", $term->tid)) ;
      if ($result) {
        $mid = $result;
      }
    }
    if ($mid > 0) {
      // Follow the parents up the chain to get the trail.
      while ($mid && ($item = menu_get_item($mid))) {
        $location[] = $item;
        $mid = $mid = $item['pid'];
      }
      $location = array_reverse($location);
      $location[] = array('path' => 'node/'.$node->nid, 'title' => $node->title);
    }
    return $location;
  }
}

Could you please tell me if my snippet will cause me troubles? Like breaking something, or in some cases won't work?

What do you think? Thank you guys!
Jérémy

caktux’s picture

I needed to make Menutrails work with i18n also, but for content types. Since I'm using translated menu items, translated content types had to be associated with their translated menu items... Quite complex, but using jchatard's idea, here's how I fixed this :

function menutrails_node_location($node) {
  // this should only fire if the menu isn't already active
  $item = menu_get_item(NULL, 'node/'.$node->nid);
  // type = 4 is for a callback
  if ($item['type'] == 4) {
    $type_trails = variable_get('menutrails_node_types', array());
    $mid = $type_trails[$node->type];

    $result = db_result(db_query("SELECT path FROM {menu} WHERE mid = '%s'", $mid));
    if ($result) {
      $trans_path = translation_url($result,i18n_get_lang());
      $trans_result = db_result(db_query("SELECT mid FROM {menu} WHERE path = '%s'", $trans_path));
      if ($trans_result) {
        $mid = $trans_result;
      }
    }

    $term_trails = variable_get('menutrails_terms', array());
    foreach($node->taxonomy as $tid => $term) {
      if ($term_trails[$tid] > 0) {
        $mid = $term_trails[$tid];
      }
    }
    if ($mid > 0) {
      // Follow the parents up the chain to get the trail.
      while ($mid && ($item = menu_get_item($mid))) {
        $location[] = $item;
        $mid = $mid = $item['pid'];
      }
      $location = array_reverse($location);
      $location[] = array('path' => 'node/'.$node->nid, 'title' => $node->title);
    }
    return $location;
  }
}

Added the part right under $mid = $type_trails[$node->type];.

Hope it can help someone :)

osopolar’s picture

What do you think about this solution:

For each language I show different Menu-Items (thats the way i18n is doing menu internationalization).
I.e. one menu item is called foo and its translation is bar, so i have for the first language the item foo and for the second language the item bar. Now I want to assign active trail by category. For that I have the vocabulary called "menu" with the item foo and its translation bar. With the current version I can do the adjustment for foo, but when I'll do it for bar (by changing the language) the foo settings will be deleted ... it's because the menutrails_terms variable will be overwritten for each time it get saved.
That's why I use for every language another variable i.e. menutrails_terms_en (for english) menutrails_terms_es (for spanish) ... . The i18n module has some mechanism for saving language dependent variables ... but at the moment I'm not using (I think it would be better, but at the moment my way is more comfortable to me).

I needed to change the following code:


function menutrails_node_location($node) {
  // this should only fire if the menu isn't already active
  $item = menu_get_item(NULL, 'node/'.$node->nid);
  // type = 4 is for a callback
  if ($item['type'] == 4) {
    $type_trails = variable_get('menutrails_node_types', array());
    $mid = $type_trails[$node->type];
    
    // this is the language dependent part
    $lang = '';
    $menutrails_terms = 'menutrails_terms';
    if (module_exists('i18n')) {
      $lang = i18n_get_lang();
      $menutrails_terms = $menutrails_terms.'_'.$lang;
    }
    
    $term_trails = variable_get($menutrails_terms, array());
    foreach($node->taxonomy as $tid => $term) {
      if ($term_trails[$tid] > 0) {
        $mid = $term_trails[$tid];
      }
    }
    if ($mid > 0) {
      // Follow the parents up the chain to get the trail.
      while ($mid && ($item = menu_get_item($mid))) {
        $location[] = $item;
        $mid = $mid = $item['pid'];
      }
      $location = array_reverse($location);
      $location[] = array('path' => 'node/'.$node->nid, 'title' => $node->title);
    }
    return $location;
  }
}

And also I needed to change the settings form:

function menutrails_settings_form() {
  $lang = '';
  $menutrails_terms = 'menutrails_terms';
  if (module_exists('i18n')) {
    $lang = i18n_get_lang();
    $menutrails_terms = $menutrails_terms.'_'.$lang;
  }

...

  $term_trails = variable_get($menutrails_terms, array());

...

foreach ($vocabs as $vocab) {
    $form[$vocab->vid][$menutrails_terms] = array(
      '#tree' => TRUE,
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Menu trails by category:'). " $vocab->name",
    );
    $terms = taxonomy_get_tree($vocab->vid);
    foreach ($terms as $term) {
      $form[$vocab->vid][$menutrails_terms][$term->tid] = array('#type' => 'select',
        '#title' => t('Parent item for'). " $term->name",
        '#default_value' => $term_trails[$term->tid],
        '#options' => $options,
      );
    }

...
I think for the content type assignment it would be the same way.
So what do you think about? May you test it?
One thing we need to do is to delete the menutrails_terms_?? variables by the uninstaller to keep drupals variable table clean. I did not had time to do that, sorry.

obuone’s picture

Hello,

I can confirm solution from post #3 works for categories on Drupal 5.7 with menutrails 5.x-1.x-dev.

Thanks alot !

davyvdb’s picture

For the node types part I have replaced all instances of 'menutrails_node_types' by 'menutrails_node_types' . i18n_get_lang().

if you now go to the settings form for each language, you'll be able to set the menu item for each language / content type combo.

laiska’s picture

Because I'm lazy and I don't want to code, I just added 'menutrails_terms' to i18n_variables in my sites settings.php file.
Just as advised in http://drupal.org/node/134002 .

$conf['i18n_variables'] = array(
// Site configuration
'site_name',
'menutrails_terms' );

This makes the Menu Trails configuration language dependent and the setting will be saved separately for each language.

It works just fine with Drupal 5.7 and Menu Trails 5.x-1.x-dev

ar-jan’s picture

Great call laiska, being lazy can be a good thing :)

This trick works also for D6, but you have to use menutrails_menu, not menutrails_terms.
[[edit: hm not true, actually we need both menutrails_menu and menutrails_terms, without menutrails_terms the categories settings are still wiped.]]

Are there any problems to be expected this way, or is this a perfectly acceptable solution?

Anyhow, I think it would still be a good feature for menutrails to be able to configure settings for more than one menu... (+1).

joshk’s picture

Subscribing. I'll look into this for a future release.

mediamash’s picture

i'm trying to assign the 'menu trails by NODE TYPE' to a multilanguage i18n block for each seperate language. The code below doesn't seem to do the trick ...

$conf['i18n_variables'] = array(
  'menutrails_menu',
  'menutrails_node_types',
  'menutrails_terms',
);
mediamash’s picture

when i check the database 'i18n_variable' it doesn't contain 'menutrails_xxx' rows. The only thing you have to do is adjust the setting.php with the code above + set the values for each language, right?

-Anti-’s picture

> This trick works also for D6, but you have to use menutrails_menu, not menutrails_terms.
> [edit: hm not true, actually we need both menutrails_menu and menutrails_terms,
> without menutrails_terms the categories settings are still wiped.]

I could do with some help with this please, if you have a moment.

In settings.php I have:

$conf['i18n_variables'] = array(
// Site name, slogan, mission, etc..
'site_name',
'site_slogan',
'site_mission',
'site_footer',
'anonymous',
// Different front page for each language
'site_frontpage',
// Primary and secondary links
'menu_primary_menu',
'menu_secondary_menu',
'menu_primary_links_source',
'menu_secondary_links_source',
// Contact form information
'contact_form_information',
// Menu Trails
'menutrails_menu',
'menutrails_terms'

);

On the menu trails page I see 'This is a multilingual variable' for the 'Menutrails Menu:' part.
I can select two different menus here by switching language.

However, below that, when I try to save separate 'node-types' from each menu, it only saves one. In other words, when I switch to the second language and choose menu-items for each content-type, saving them wipes the previously saved english choices - so when I switch back to english the content-types are set to < none >.

Did anyone get this working properly?
Thanks!

EDIT:
I tried adding 'menutrails_node_types' even though mediamash said it didn't work, and it seems to be OK!
If this truly does function properly, I'm going to be a very happy chappy.
I wish I'd seen this thread five days ago.

mediamash’s picture

yes indeed it works - i was editing the wrong setting.php file for that

sun’s picture

Please submit a proper patch. See http://drupal.org/patch for details.

sun’s picture

Status: Active » Closed (won't fix)

Sorry, Menu Trails for Drupal 5 is not actively developed/maintained anymore. Only issues containing patches may still be considered. Feel free to re-open this issue if you want to provide a patch.