[development] Extending menu objects to store node translations

Frank Steiner fsteiner-mail1 at bio.ifi.lmu.de
Thu Jun 26 08:46:40 UTC 2008


I would like to discuss if menu objects could be extended to store
pointers to a node and all of its translations. Some other people but
me would like to see that, too, see http://drupal.org/node/230868

Why could such menus make sense?

At our site most stuff is language neutral because as long as we don't
have e.g. a translation of the english research site, we show it for
all languages. But for the teaching sites, we need english and german

But we have nodes with menu entries and those menu entries have
children. A menu looks like

"Programming Course A"
 |- Material for Practice 1
 |- Material for Practice 2

The "Material pages" just contain code snippets or PDFs for download,
they don't have lot of text, so they don't have to exist for two
languages. The nodes are language neutral.

But the "Programming Course A" node contains a lot of explanations so
it must exist in english and german. The problem is clear: When I
translate this node I must give the translation a new menu item
"Programmierung Kurs A" so that a menu item appears when switching the
language. But then the whole "Material" subtree is gone for this new
menu item.  So I would have to create translations for all "Material"
nodes, attach the attachments once again and put all those translated
nodes below "Programmierung Kurs A". Useless, since the "Material"
nodes wouldn't change but just be duplicated.

What I would like to have is a menu object that can store pointers to
the translated versions of the node it points to, too. Then when
swichting the language, the menu system could check if a translated
version for the nodes exists and keep showing the menu item. If the
menu string was localized, it could display the translated version (as
works already). This way, the "Material" subtree would stay because
all translated nodes would have the same single menu item.

This wouldn't be hard to do. With changing a bit of code in the i18n
menu, I already achieved that the menu item changes its href to the
path of the translated node, so with translating the menu string, the
menu item "Programming Course A" pointing to "node/xx" changed to
"Programmierung Kurs A" and points to "node/yy".

The only problem: When I'm viewing the translated node, the function
menu_tree_page_data in menu.inc rebuilds the tree by searching for the
menu object of the node it currently shows. Since the translated node
doesn't have an own menu item, menu_tree_page_data shows the
"Programming Course A"/"Programmierung Kurs A" item but doesn't unfold
its subtree because it doesn't realize it is connected to the current

I think all that would be neccessary for a conservative extension not
destroying anything else was extending the menu object by another
array to store the links to the translated nodes. When translating
nodes, you could have a checkbox to "reuse the menu item" or
sth. menu_tree_page_data would just have to check that array, too,
when looking for connections between the currently showing node and
the menu system.

I consider hacking this for our own site, but I would like to know if
there are chances that the menu system could be extended this was for
drupal 7.

What do you think about the idea?


Dipl.-Inform. Frank Steiner   Web:  http://www.bio.ifi.lmu.de/~steiner/
Lehrstuhl f. Bioinformatik    Mail: http://www.bio.ifi.lmu.de/~steiner/m/
LMU, Amalienstr. 17           Phone: +49 89 2180-4049
80333 Muenchen, Germany       Fax:   +49 89 2180-99-4049
* Rekursion kann man erst verstehen, wenn man Rekursion verstanden hat. *

More information about the development mailing list