Hi,
since no one has cared about the non-functioning i18nmenu in 6.x. for a long time, I tried to patch it myself, but I'm stuck. If some developer who knows what i18nmenu should finally do is willing to support me, I might be able to get things fixed.

I expect localized menus to work as follows:
I create a new page "E" in english language with a menu title "English" in my custom menu. Then I localize that string to "German". Then I create a german translation "G" of my page and don't chose a menu title for it (otherwise I would end up with two menu entries). Now I expect to see "English" in my menu, pointing to E. When I switch language to german, I expect to see "German" in my menu, pointing to G.
If I have some children of the "English" menu entry that point to language neutral pages, I expect those children to stay when switching language, i.e. see the children below menu entry "German", too, since it is the same menu entry, just localized. That would be the main difference to giving the german translation of the page an own menu title and thus a different menu entry!

Is that correct? If not, forget the rest of this post and explain to me how it should work :-) I cannot think of a different way that makes a difference to chosing an own menu title for every translation (and then I didn't need i18nmenu).

What I did so far:

  • increased module weight of i18nblocks.module (and to be sure, also i18nmenu). Otherwise nothing ever localizes because i18nblocks_theme is responsible for calling i18nmenu_translated_tree for every block which finally translates menus. But the system module is loaded after i18nblocks and does return array_merge(drupal_common_theme(), array(..., thus rewriting the blocks theme from i18blocks with the defaults from drupal_common_theme.
  • Now i18nmenu_localize_tree tries to replace $tree[$index]['link']['title']. But that never happens
    if we have language mode 'simple' (current language and no language) and our current language is german. Then we get only the list of menu entries that point to nodes with language german or no language.
    But our german page G has no menu entry, only the english page E. Therefore I set i18n_selection_mode('off'); in i18nmenu_translated_tree to fetch all menu entries (could do better like fetching only those for that a translated version of the current language exist).
  • Now I filter the menu entries in i18nmenu_localize_tree as follows:
    • if the node the menu entry points to has a language which is the current language, keep the entry
    • if it has no language, keep the entry (for mode 'simple',. must be finegraned for other modes)
    • if node has a different lang than the current, localize the title with the tt function (original code of i18nmenu_localize_tree ). If the title does not localize, unset the menu entry. We can't show it if there is no localized string for our current language
    • if the menu title localizes check for a translated version of the node in our language (using translation_translation_link_alter for $link['href']. If a translated version for current language exists, I replace the href by
      $tree[$index]['link']['href']=$trans_links[$current]['href'];
      so that the localized menu entry points to the translated version.
  • That does work for top level menu entries. But if the original "English" menu entry has menu childen, the localized menu entry "German" has not, and as far as I see things start to go wrong in menu_tree_page_data. When I'm viewing page "G", the submenu should unfold below the "German" menu. But menu_tree_page_data loads the "menu item corresponding to the current page" and then searches children for this menu item etc.

    BUT: our current page G doesn't have a menu entry, because menu item "German" is no a real, own menu item, but only the localization of the "English" menu. So no menu item is found for G and therefore no menu children are created for menu item "German".

Thus, the idea of a page and all translations being bound to one menu entry with localized menu title, cannot work this way.

But if we localize only the menu title without changing the href, then the menu title would change to e.g. "German" but still point to E instead of G. So this can't be the idea of localized menus I guess.

The only way it would work at the moment was to create only language neutral pages, localize their menu entries and write the content of all languages on one page. There was some patch or module that I currently don't find where you would write sth. like

==en==
This is shown when language is english
==de==
Das sieht man wenn die Sprache deutsch ist

so that only the part of the page matching the current language is shown.

Comments

fletchgqc’s picture

Hi Frank,

I must admit that was a long post and some of it was beyond me.

But anyway, I'm running D6 and what I do is just create English menu items pointing to the English pages, and German menu items pointing to the German pages. When you are on an English page, you only see English menu items and when you are on a German page you only see German menu items.

This works perfectly for me. Technically the English and German menu items are not related (as translations of one another), but what does it matter? It works.

Anonymous’s picture

The problem is that submenus cannot be shared among unrelated menu items.

Thus, if you have some language-neutral pages connected below the English menu a, all those menu children will disappear when you switch to German. And there's no way to connect them there because you cannot have to menu parents for those language-neutral pages.

And that's what we have here: Some menu items that are available in two languages, while many (not all) of their children are not yet available in two languages or will never be.

Such a mixed tree would be possible with localized menus (if I get their function right) but not with unrelated menu items for different languages. But of course, so far I've no found anyone whould would tell me how localized menus should work. Maybe my understanding is wrong.

fletchgqc’s picture

Aha. I see. Well I don't have any language-neutral items so my solution should be fine for me. Thankyou for that info - helps me to know I'm not doing something wrong. As to the original intent of your request... sorry I can't help!

fletchgqc’s picture

.... other than to say that there are heaps of issues lingering around the issues queue associated with i18n variables on the whole.

Anonymous’s picture

Well, yes, looks like the 6.x version of i18n is kind of unmaintained at the moment. That's why I tried to sth. myself. But as long as no one can even explain what i18menu is supposed to do exactly, I'm might be trying to fix things the wrong way :-(

fletchgqc’s picture

Zarevac’s picture

I encountered the same problem. It appears as if the menu's after being created in the admin section show up regardless what language you selected them in.

Anonymous’s picture

@#6: Honestly, I'm not sure about the difference of menu title localized by drupal core and by i18nmenu. Someone needs to clarify this so that I can try going on.

miopa’s picture

@#8

Core translation is used for just changing the appearance of the menu item. It's the same menu item, pointing to the same path, but is displayed on screen using different language.

I use i18nmenu localization when I need to point to different paths (for the same logical item). So different menu item for each language is created, pointing to a different path (and is displayed just for the specified language).

Frank Steiner’s picture

Hmm, I'm not sure this is really true for user defined menu items because when they point to a language neutral page and the menu titel is translated, it doesn't change without i18nmenu. So it looks like menu core translation only translates predefined menu items but not user created ones. When I turn on i18nmenu, the menu item translates, so I now at least have one case where I really need i18nmenu :-) And finally I guess I understood that i18nmenu isn't meant to do more but this.

jose reyero’s picture

Status: Active » Fixed

> So it looks like menu core translation only translates predefined menu items but not user created ones.

Right

I think the i18nmenu module is working, please create more specific issues if any.

Frank Steiner’s picture

Hi Jose,

most of this just came up because I wasn't sure what i18nmenu should do. I expected it to more that it acutually can, i.e., not only localize the menu title, but also let the menu item point to the translation of the page. I understood in the meantime that this cannot be done without violating menu logic, so I'm fine with i18nmenu :-)

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Alice Heaton’s picture

Hey ! I've raised an issue specifically about the weight of the i18nblocks module ; and I've provided a patch to the install file and to the admin page (so the weight can be changed manually). Hopefully it will have more chance of being looked into if it is it's own specific issue.

It's here : http://drupal.org/node/299642

Thanks :)