Hello, first sorry for my bad english, i have made a little patch in menu.inc which allow menu items with same path to be created in each language, here's an example of this usage :
- You have drupal with i18n and panels module enabled
- You have two language enabled in your website (english and french by example)
- You create a content translated in all languages of your website
- You create a panel page with the url 'panel' and add the node you created in the step above (in default language to let panels choose the translated version of the node in current language)
- Now, if you go to 'panel', you will have the panel page with the node inside in the good translation
- You create another content translated in all languages (with menu item for each translation in primary-links) => i call it 'parent'
- You add for each menu item of content 'parent' a menu item which points to 'panel' and in the language of 'parent' menu item
- Now, in the primary-links, you have :
+ parent (in english, points to node parent in english)
-+ panel (in english, points to panel)
+ parent (in french, points to node parent in french)
-+ panel (in french, points to panel)
- Now you have the choice : you can set source of secondary-links to primary-links and show secondary-links in your theme OR you can create (with the module 'Menu Block') a menu block of primary-links with level 2 to show child items)
- So you have for each language the item 'parent' with the sub-item 'panel'
- When you click on 'parent' item (in any language), you will see the panel sub item as expected
- If you click on the 'panel' sub item (in english language if the content has been created in english language first), you will see the panel and menu is always ok
- BUT if you click on the 'panel' sub item in other language (not the first created), the sub item will disappear
It's because menu functions doesn't see the difference between menu items with same path and different languages (it doesn't care about language)
That cause also problems with breadcrumb when you need similary structure.
So i have write a little patch in menu.inc (in menu_tree_page_data function) :
Replace
static $tree = array();
by :
global $language;
static $tree = array();
Then replace :
// Generate a cache ID (cid) specific for this page.
$cid = 'links:'. $menu_name .':page-cid:'. $item['href'] .':'. (int)$item['access'];
by :
// Generate a cache ID (cid) specific for this page.
$cid = 'links:'. $menu_name .':page-cid:'. $item['href'] .':'. (int)$item['access'] . ':langcode:' . $language->language;
Then replace :
$parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path IN (". $placeholders .")", $args));
by :
if ($result = db_query("SELECT options, p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path IN (". $placeholders .")", $args)) {
while ($link = db_fetch_array($result)) {
// Get options array
$options = unserialize($link['options']);
// If langcode is current language or no language, add this parent
if ((!(isset($options['langcode']))) || ($options['langcode'] == $language->language)) {
// Remove options in array
unset($link['options']);
// Set parent
$parents = $link;
break;
}
}
}
Then replace (maybe not necessary) :
$parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, $item['tab_root']));
by :
if ($result = db_query("SELECT options, p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, $item['tab_root'])) {
while ($link = db_fetch_array($result)) {
// Get options array
$options = unserialize($link['options']);
// If langcode is current language or no language, add this parent
if ((!(isset($options['langcode']))) || ($options['langcode'] == $language->language)) {
// Remove options in array
unset($link['options']);
// Set parent
$parents = $link;
break;
}
}
}
This patch needs review but normally it's ok, it doesn't cause problems with website without multilingual support.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | menu-language-12-D6.patch | 4.55 KB | NROTC_Webmaster |
| #7 | node-front.jpg | 14.27 KB | chaugi |
| #6 | panel-d7.jpg | 37.46 KB | chaugi |
| #4 | panel.jpg | 39.15 KB | chaugi |
Comments
Comment #1
chaugi commentedI have had same issue, why this patch is not included in drupal core update?!
Comment #2
dddave commentedThis would need a proper patch file to review. http://drupal.org/patch/create
And it should be tested with the latest builds of Drupal 6, i18n and Panels. Does this problem still exist?
AND: I don't understand the problem totally as I am not too invested in this issue (just stumbled upon this issue report) but I suspect that Panels provides a workable solution already.
Comment #3
aekarpenko commentedIt's not just language related. Drupal menus fail if you [have] any two menus point to the same node, whether they are within the same menu, or in completely different menus. See: http://drupal.org/node/609542
Comment #4
chaugi commented@dddave
The problem still exists. It is hard to describe, but as in our country we mainly create only multilingual sites the problem arises from time to time :( The reason why this problem happens is probably because of the paths.
For e.g. each node has internal path node/nid. But for example, views and panels has no nid they have just path for all languages. And it appears that if you create panel with path like for e.g "secondary" and place this as child of primary links item and in settings specify "Source for the secondary links: Primary links" you will see that going to this menu item, menu item will be lost.
I have a dump of Files and DB of example, which recreates this situation, so you won't need to create it by yourself.
Drupal 6.19
Panles 3.8
Ctools 1.8
i18n 1.7
All in one files (2.53 MB): http://www.rasayana.lv/test.zip
DB (173 KB): http://www.rasayana.lv/test-db.zip
If you go to:
http://localhost/test/ru/secondary
http://localhost/test/lv/secondary
menu Item will be lost
P.S. I have tried to apply modifications as described above but this does not solve the problem, so this "patch" does not work.
Comment #5
dddave commentedOk, I guess I understand the problem now. Anyways: As long as nobody can provide a killer patch for this nothing will happen.
Has anyone checked if the problem persists in D7?
Comment #6
chaugi commented1. With D7 is a bit different. Menu does not disappear.
But if your language (in this example) is Latvian or English and you are on appropriate language node, Sample LV (Latvian language) and you click on Panels LV (Sample LV submenu item, points to Panel page with url: /secondary, containing translated node), last menu item is activated (Sample RU), but Sample LV should be active.
Drupal 7, beta 3
Ctools 1.0-alpha1
Panels 3.0-alpha1
All in one files (4.00 MB): http://www.rasayana.lv/test2.zip
DB (242 KB): http://www.rasayana.lv/test2-db.zip
2. One more interesting thing with menu. If my language is Latvian (see URL), but I am on node with different language, link item showing current language is inactive on language switch block.
Comment #7
chaugi commentedOne more bug in Drupal 7 beta3. In case in "Site information" I set Drupal default page to one translated node, e.g. Sample EN, and on front page switch the language from English to Russian nothing is going to be changes, neither translation nor active tab (in Bartik theme)
Comment #8
chaugi commentedThis issue is resolved using the following patch:
http://drupal.org/node/609542#comment-3425724
I have tested by myself on Drupal 6.19. Should be included in core.
Comment #9
chaugi commentedI there the way to speed up this problem solution, should I post somewhere else?!
Comment #10
dddave commentedThe only way to speed things up is to provide a patch.
Comment #11
rvilarSubscribing
Comment #12
NROTC_Webmaster commentedI think this has already been fixed in D7/D8 but here is a patch for D6 based on the code listed.
Comment #22
catchBased on #12, closing this as outdated.