I've been trying various ways to make Taxonomy Menu generate menu items for my localized or translated taxonomies. No joy.
Regardless of the settings, I'm getting the menu items in one bunch attached to one menu.

So for translated taxonomies, instead of:

Menu (EN + FR)
  Parent Menu Item EN
    Term 1 EN
    Term 2 EN
  Parent Menu Item FR
    Term 1 FR
    Term 2 FR

I'm getting:

Menu (EN + FR)
  Parent Menu Item EN
    Term 1 EN
    Term 2 EN
    Term 1 FR
    Term 2 FR
  Parent Menu Item FR

for localized taxonomies I'm getting menu items for one language only, misplaced, such as:

Menu (EN + FR)
  Parent Menu Item EN
    Term 1 FR
    Term 2 FR
  Parent Menu Item FR

I looked into the code and specifically into this line of taxonomy_menu.module:
if(isset($taxonomy_entity->translations) && isset($taxonomy_entity->translations->original))
Regardless of the i18n model of a taxonomy vocabulary, I could not get to see the ->translations property in my dpm(). Maybe I was doing something wrong, but the docs are pretty modest if not outdated. Then I gave a thought to how I would expect the taxonomy menu to communicate and work. I came to the following conclusion:

Desired modification

I believe TM should act differently based on the i18n model of the selected parent menu item (Fixed Language or Localize and Translate). So:

  1. The Menu Item dropdown should be renamed to "Menu Item (source language)
  2. Upon selecting, the form would examine the menu model of the selected menu item, and if:
    • fixed language - display additional rows for selecting menus for each enabled language. User would have to manually indicate the parent item for each language
    • localize and translate - no additional visual feedback; TM would pick up the menu translation set of the source language and place the menu items into the appropriate translated menu item.

Let me know if I'm wrong. I just wish I was skilled enough to write a patch.

Comments

moniuch’s picture

Issue summary: View changes

text formatting

dstol’s picture

Can yo give it a shot with 7.x-2.x? Support for i18n is greatly improved there.

moniuch’s picture

In fact, I did yesterday, but was slapped with a bunch of errors. Unfortunately all patches I found here (an issue with similar problem), did not apply. Maybe a fresh build would help, please?

hles’s picture

None of the patches you mention have been rewritten against 7.x-2.x unfortunately. See the discussion over here http://drupal.org/node/1665308

moniuch’s picture

I just wanted to give another shot to current 2.0-alpha and this is the error:
Parse error: syntax error, unexpected T_FUNCTION in /demo/startint/sites/all/modules/taxonomy_menu/taxonomy_menu.admin.inc on line 326
What is wrong about that line?
array_walk_recursive($options, function($a, $b) use (&$flatten) { $flatten[$b] = $a; });

moniuch’s picture

OK, I commented this line out (as it is PHP 5.3), just to get the module to work and check out the changes. However, except for some reorganization at the Content Type vertical tab form, I could not see any improvement with regard to i18n. Moreover, the module failed to rebuild my menu items (possibly due to my uncommenting the line).

Notice: Undefined offset: 1 in taxonomy_menu_vocab_submit() (line 186 of /demo/startint/sites/all/modules/taxonomy_menu/taxonomy_menu.admin.inc).
Notice: Undefined index: rebuild in taxonomy_menu_vocab_submit() (line 227 of /demo/startint/sites/all/modules/taxonomy_menu/taxonomy_menu.admin.inc).

At any rate the alpha is unusable to me at this point, so I will stay back before I employ 2.x on a production site. Hopefully you will find time to review my original post and implement the suggestion.

hles’s picture

There is a misunderstanding here, absolutely no i18n feature has been implemented in either 1.x or 2.x. It's just that 2.x should eventually allow to add i18n features more easily.

johnv’s picture

Title: i18n support for selecting parent menu item » [i18n] multi-lalnguage support for selecting parent menu item

Working through the issue queue: harmonizing issue titles.

dmaciej’s picture

I've got some workaround for 1.4. You must change the base function with the following one:

/**
 * Adds/Updates a taxonomy menu item.
 *
 * We use a custom data array $item as a parameter, instead of using a
 * standard taxonomy $term object. This is because this function is also
 * called from hook_taxonomy(), which doesn't have a $term object. Rather
 * have one consistent method of passing the data.
 *
 * @param $item
 *   array with the following key/value pairs:
 *     'tid' => the term id (if 0 then adding the vocab as an item)
 *     'name' => the term's name
 *     'description' => term description, used as to build the title attribute
 *     'weight' => term weight
 *       (This will be overriden by the order created from taxonomy_get_tree which respects the correct wight)
 *     'vid' => the vocabulary's id
 *     'ptid' => the term's parent's term id
 *     'menu_name' => the menu that the link item will be inserted into
 *     'mlid' => if this is filled in then the mlid will be updated
 */

function _taxonomy_menu_save($item)
{
  $insert = TRUE;
  $flatten_menu = variable_get(_taxonomy_menu_build_variable('flat', $item['vid']));

  // Child items should appear around the parent/root, so set their weight
  // equal to the root term's

  if ($flatten_menu) {
    $item['weight'] = $item['root_term_weight'];
  }

  // create the path.

  $path = taxonomy_menu_create_path($item['vid'], $item['tid']);

  // get the parent mlid: this is either:
  // - the parent tid's mlid
  // - the vocab menu item's mlid
  // - the menu parent setting for this vocab

  $plid = _taxonomy_menu_get_mlid($item['ptid'], $item['vid']);

  if (!$plid || $flatten_menu) {
    $plid = variable_get(_taxonomy_menu_build_variable('vocab_parent', $item['vid']) , NULL);
    if ($original = menu_link_load($plid)) {
      $languages = i18n_language_list();
      $result = db_select('menu_links', 'l')
         ->fields('l', array(
           'mlid',
           'language'
         ))->condition('l.i18n_tsid', $original['i18n_tsid'])
           ->condition('l.language', array_keys($languages) , 'IN')
           ->execute();
      $plids = array();
      while ($record = $result->fetchAssoc()) {
        $plids[] = array(
          'language' => $record['language'],
          'mlid' => $record['mlid'],
        );
      }
    }
  }
  else {
    $plids = array($plid);
  }

  // Make sure the path has less then 256 characters

  if (drupal_strlen($path) > 256) {
    preg_match('/(.{256}.*?)\b/', $path, $matches);
    $path = rtrim($matches[1]);
  }

  $mlids = array();
  foreach($plids as $key => $plid) {
    $link = array(
      'link_title' => $item['name'],
      'menu_name' => $item['menu_name'],
      'options' => array(
        'attributes' => array(
          'title' => trim($item['description']) ? $item['description'] : $item['name']
        )
      ) ,
      'weight' => $item['weight'],
      'module' => 'taxonomy_menu',
      'expanded' => variable_get(_taxonomy_menu_build_variable('expanded', $item['vid']) , TRUE) ,
      'link_path' => $path,
    );

    // Add setup the query paramater in the URL correctly

    if (strpos($path, '?') !== FALSE) {
      $split = explode('?', $path);
      if (strpos($split[1], '?') !== FALSE) {

        // the query split didn't work, too many question marks
        // error?

      }
      else {
        parse_str($split[1], $link['options']['query']);
        $link['link_path'] = $split[0];
      }
    }

    // If passed a mlid then add it

    if (isset($item['mlid']) && $item['mlid']) {
      $link['mlid'] = $item['mlid'];
      $insert = FALSE;
    }

    // FIXME: i18nmenu need to be cleaned up to allow translation from other menu module

    if (module_exists('i18n_menu')) {
      $link['options']['alter'] = TRUE;
      $link['language'] = $plid['language'];
      $link['customized'] = 1;
    }

    // set the has_children property
    // if tid=0 then adding a vocab item and had children
    // if the term has any children then set it to true

    if ($item['tid'] == 0) {
      $link['has_children'] = 1;
    }
    else {
      $children = taxonomy_get_children($item['tid']);
      if (!empty($children)) {
        $link['has_children'] = 1;
      }
    }

    // If remove is true then set hidden to 1

    $link['hidden'] = (isset($item['remove']) && $item['remove']) ? 1 : 0;
    $link['plid'] = $plid['mlid'];
    if ($mlid = menu_link_save($link)) {
      $mlids[] = $mlid;
      if ($insert) {
        _taxonomy_menu_insert_menu_item($mlid, $item['tid'], $item['vid']);
      }
    }
  }
  if (!$mlids) {
    drupal_set_message(t('Could not save the menu link for the taxonomy menu.') , 'error');
    return FALSE;
  }
}
dmaciej’s picture

Issue summary: View changes

provided more detail

SandraVdv’s picture

After applying the patch in #88 everything works great, but when I submit a term that doesn't have a description I get this notice:

Notice : Undefined offset: 0 dans _taxonomy_menu_term_field_value() (ligne 498 dans /Applications/MAMP/htdocs/woonportaal/sites/all/modules/patched/taxonomy_menu/taxonomy_menu.module).

This is my patch to solve that issue:

diff --git a/taxonomy_menu.module b/taxonomy_menu.module
index d898319..11adab0 100644
--- a/taxonomy_menu.module
+++ b/taxonomy_menu.module
@@ -493,7 +493,10 @@ function taxonomy_menu_entity_translation_delete($entity_type, $entity, $langcod
 function _taxonomy_menu_term_field_value($term, $field_name, $langcode, $field_formatter = 'text_plain', $settings = array('trim_length' => '100')) {
   $display = array('label' => 'hidden', 'type' => $field_formatter, 'settings' => $settings);
   $field_item = field_get_items('taxonomy_term', $term, $field_name, $langcode);
-  $field_value = field_view_value('taxonomy_term', $term, $field_name, $field_item[0], $display, $langcode);
+  $field_value = '';
+  if ($field_item) {
+    $field_value = field_view_value('taxonomy_term', $term, $field_name, $field_item[0], $display, $langcode);
+  }
   $field_rendered = ($field_formatter == 'text_plain') ? render($field_value) : strip_tags(render($field_value));
   return $field_rendered;
 }

Maybe this can be integrated in the patch for the i18n issue as well?

Sorry, this comment was meant for the issue https://drupal.org/node/1665308, but I can't delete it here?

vladimiraus’s picture

Status: Active » Closed (outdated)

Thank you for your contributions.
Drupal 7 is no longer supported.
Closing this issue as outdated.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.