2

I have menu structure like this:

Home | About | Products

if a user is currently on English page then I need like this:

Home | About | Products | Swedish

and if a user is currently on Swedish language then it will show like:

Home | About | Products | English

1: So how can I add a menu switcher link to the main menu which shows only one language link at a time? 2: What will be the pate for each of the language in the path field while adding a menu link.

2

You have two ways of doing this, one is to use HTML/CSS to position the language switcher block in the menu, probably a little harder to do with a variable length menu unless you right align it.

Two would be to add the language switcher to the menu, you can use something like http://www.liquidcms.ca/how-to-language-switcher-menu-item to do that.

  • I am actually using dropdown menus on my site. I guess the first option is not possible to append the language switcher to the main-menu. 2nd I am new to drupal and coding as well. – mbkh10 Sep 26 '13 at 15:39
  • That's probably your theme or modules doing something, by default it's just two text links. – Steven Sep 26 '13 at 15:43
  • You're going to want to read up on drupal.org/node/361112 it will let you know how to properly do this. Basically you'll want a new custom module with that PHP (in the url above) in there. If you need more help just ask. – Steven Sep 26 '13 at 15:45
  • While adding a menu item for language what should I write in the path field ? like mysite/en or mysite/sv – mbkh10 Sep 26 '13 at 15:46
  • That is another option if you don't mind not keeping the current path. – Steven Sep 26 '13 at 15:48
2

Menu per language module will have the option

This module enables you to have an clear overview per language what the menu entries are. In Drupal all of these links are on the same page and thus it is not clear in which language it is and the menus will grow very big in time aswell.

  • I have made two menu blocks one for each language. Now all I need al-least is to change the url from "mysite/?q=en" to "mysite/?q=sv" when a user click the menu item "Swedish". How can I do that? – mbkh10 Sep 27 '13 at 10:39
2

I have solved my problem with the help of a friend. I have created a list of two menus lists using menu-block module. One set of English menus and one set of Swedish menus in the following order.

Home | About | Products | Svenska

enter image description here

and for Swedish

Hem | OM | Produkter | English

After creating the menus , I was unable to provide URL or link to a node (/node/3) OR language (/?language=en) in the path field while creating the link item.

In my case if I change the language such as (http//mysite.com/?q=en) to (http//mysite.com/?q=sv) the above created Swedish menu-block appears. As Swedish menu-block was enabled on Swedish language and English on English menu-block. After that I change one of the hook available in the main theme to my requirement.

I used yourtheme_menu_link() hook in template.php file. Under the set of if statements I added this block.

    if ($element['#original_link']['mlid'] == 2662) {
    global $language;
     $lang = $language;
     $lang->prefix = "en";
    $special_link = '<a href="' . url('<front>', array('language' => $lang)) . '">English</a>';
} else if ($element['#original_link']['mlid'] == 2675) {
    global $language;
     $lang = $language;
     $lang->prefix = "sv";
    $special_link = '<a href="' . url('<front>', array('language' => $lang)) . '">Svenska</a>';
}

if (at_get_setting('extra_menu_classes', $theme_name) == 1 && !empty($element['#original_link'])) {
  if (!empty($element['#original_link']['depth'])) {
    $element['#attributes']['class'][] = 'menu-depth-' . $element['#original_link']['depth'];
  }
  if (!empty($element['#original_link']['mlid'])) {
    $element['#attributes']['class'][] = 'menu-item-' . $element['#original_link']['mlid'];
  }
}

Here 2662 and 2675 is the menu item id. This may help if someone need. It solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.