How to use i18n for menu link to "blog" (D6)
I am running a trilingual blog on a charity website on Drupal6 + i18n module but can't configure the primary link to the blog to show up in the choosen language only.
Internationlisation is working like charme for the blog:
www.artandaid.org/en/blog/1 => blog shows up in English
www.artandaid.org/de/blog/1 => blog shows up in German
www.artandaid.org/blog/1 => blog shows in the users language
Wonderful!
Now I would like to add two links to the primaries
Our Blog => en/blog/1
Unser Blog => de/blog/1
But I keep recieving the error message "The path 'en/blog/1' is either invalid or you do not have access to it."
When I configure the primaries like this
Our Blog => blog/1
Unser Blog => blog/1
then both menu item show up, regardless of the users language. How to filter this links for the respective language? Does anybody know a trick?
Kind regards, Michael


Try setting a language prefix for English
Probably your site's default language is English, and it has no langauge prefix. Add it at admin/settings/language > edit.
In order to only have the right menu item show I think you should do either one or both of the following:
* At admin/settings/i18n set Content selection mode to 'Only current language and no language' (you probably had already done that)
* Use i18n Multilingual menu and set the right language for the menu items 'Our Blog' and 'Unser Blog'
My solution for the (themed) menu problem
I've made the modifications you specified, but without success, and I'm starting to believe nonsie
The themed menu still shows all the translations (the block menu is working fine).
After some code digging i realized that i can filter the menus myself from the template page, adding the following code in my case in the garland theme file (themes/garland/page.tpl.php) :
<?phpforeach($primary_links as &$menuitem)
{
if(strcmp($menuitem['langcode'], $language->language) != 0)
$menuitem = null; // i don't understand why but unset($menuitem) did not work
}
?>
same thing can be applied for the secondary menu.
If you know / come across a better solution please notify me.
thanks!
Matyas
p.s. i'm sorry if i misuse some terms but 1. i'm not a native english speaker 2. i'm new to drupal (2nd day)
I may be misunderstanding
I may be misunderstanding the problem, but here is a possible solution:
Our Blog => blog/1
only that link, then create a translation (translated string) Our Blog -> Unser Blog
Not sure if this will work, and in any case I'm not 100% clear as to what the problem is.
If you wanna do this hack in
If you wanna do this hack in a cleaner fashion, consider putting this (extended-from-yours) code in your template.php's phptemplate_preprocess_page(&$vars) function:
foreach($vars['primary_links'] as &$menuitem){
if(strcmp($menuitem['langcode'], $vars['language']->language) != 0)
$menuitem = null;
}
aurels
better hack
better hack :-) (checks for language neutral menus as well, for these the language variable is empty..)
<?php$current_language = $vars['language']->language ;
foreach ( array('primary_links', 'secondary_links') as $menu_name ) {
foreach ( $vars[$menu_name] as $menu_key => $menu_item ) {
if ( $menu_item['langcode'] != $current_language && ! empty($menu_item['langcode']) ) {
unset($vars[$menu_name][$menu_key]) ;
}
}
}
?>
should add check for i18n or so.. im not sure what happens if you disable that
Check for null
Don't forget to check for null:
<?php$current_language = $vars['language']->language ;
foreach ( array('primary_links', 'secondary_links') as $menu_name ) {
if (! empty($vars[$menu_name])) {
foreach ( $vars[$menu_name] as $menu_key => $menu_item ) {
if ( $menu_item['langcode'] != $current_language && ! empty($menu_item['langcode']) ) {
unset($vars[$menu_name][$menu_key]) ;
}
}
}
}
?>
For Acquia Marina theme it is not enough. Because this theme using Drupal API function “menu_tree”. So I modified this function straight in the page.tpl.php file.
Changed one string of code:
<?phpprint menu_tree($menu_name = 'primary-links');
?>
On this one:
<?php
// Overloaded "menu_tree" function to support multilingual primary links
$menu_name = 'primary-links';
static $menu_output = array();
if (!isset($menu_output[$menu_name])) {
$tree = menu_tree_page_data($menu_name);
// Leave only current language menus and language neutral menus
$current_language = $language->language;
if ( ! empty($tree) ) {
foreach ( $tree as $menu_key => $menu_link ) {
if ( $menu_link['link']['options']['langcode'] != $current_language &&
! empty( $menu_link['link']['options']['langcode'] ) ) {
unset( $tree[$menu_key] ) ;
}
}
}
$menu_output[$menu_name] = menu_tree_output($tree);
}
print_r ($menu_output[$menu_name]);
?>
In general this is the same like in previous point, but with knowledge of menu tree structure.
checking for the module
checking for the module should be something like this, wrap the whole block in the "if"
<?phpif (module_exists('i18nmenu')) {
?>
Better hack in D6.14
Doesn't work for me. But I made this one and it works fine:
if (module_exists('i18nmenu')) {// Get the current language
$current_language = $language->language;
// Go inside $primary_links
foreach ($primary_links as $key => $menu_name ) {
//check if the menu item has the same language and if it's exists
if ( $menu_name['langcode'] != $current_language && !empty($menu_name['langcode']) ){
unset($primary_links[$key]) ;
}
}
}
Hope that could help.
loading a link.tpl.php
Hello Dzmitry I found your code and its absolutely what I was searching for to use with my menus. I have one question regarding the possibility to load a tpl.php file for the links. In my current footer menu I am calling a file called links-secondary.tpl.php which is formatting the footer links with a delimiter.
<?php print$footer_links = theme('links_secondary',menu_navigation_links('menu-footernavi'),array('class' => 'links', 'id' => 'footlist'));
?>
Is there a way to merge this with your approach?