one menu translated in multiple languages

svendecabooter's picture

Hi,

The translation of content and textual strings has much improved in Drupal 6.
However one problem that keeps popping up for most of our clients, is the translation of menus.

Most of the solutions regarding translatable menus involve having multiple menus / blocks (one per language) set up, and show them conditionally based on the current language.
However for most of our clients that's not an ideal solution. For them having to add an item to the menu multiple times is counter-intuitive.
Imagine the site has a complex menu with multiple levels... They have a nice drag & drop feature to quickly move a menu item to another parent or another level, but then they have to perform this action for all menus! If the site would have 3 or 4 languages, it's obvious that it would be hard to keep everything synchronized.

In short, the ideal solution would be:
- There's only 1 menu for the site navigation
- A user adds a node, say a page 'About Us'. When creating the node, he uses the 'Menu settings' fieldset to add the node to the menu.
- The menu contains an item 'About Us', linked to path 'node/1'.
- The user decides to translate the About Us page to Dutch. This creates a new node on the site, say 'node/2'
- Now there should be some way to have the menu automagically find the appropriate path to link to. When viewing the site in English, the menu item 'About Us' should link to node/1, while viewing in Dutch, it should link to 'node/2'.
- Furthermore the menu item label ('About Us') would have to be translatable in an easy way. Now we use the 'Menu Translation' module in the i18n package for that, which seemed to work more or less if I recall correctly.

We've been trying to write a module that provides a custom menu router to load the right node based on the current language, but that didn't turn out to be a very stable solution.
It changes the 'node/1' entry to a custom path (to call the custom menu router that comes with that), and then loads the right node based on the language. However this breaks the tabs etc... so we'd like to find a more decent way to handle this.

Does anyone have any experience with this kind of problem, or suggestions on how we can manipulate the menu system in a nice way to achieve what we want?

Thanks!

Sven

Login to post comments

I had the same question

Jax - Tue, 2008-12-16 13:47

I had the same question while using i18n with D4.7 but it seems this is a very specific use case. To use the menu in the way you describe the node has to exist in all languages before setting up the menu and that is not always the case. Technically, having a different menu per language is the most flexible solution. What you could do is alter the user interface to make sure that when a menu item is added it is also added in the other menu's. This would give it the usability you are looking for but, underneath, it would use the solution provided for i18n.

Update: Here's a D5 discussion about this:
http://drupal.org/node/76631


If there is no translation

svendecabooter's picture
svendecabooter - Tue, 2008-12-16 13:59

If there is no translation for a node, the system should use the (untranslated) source node then...
I'll check if it's easy to automatically update multiple menus when a change is made in a particular one, but it's probably not the easiest either...


I think you are right Sven,

mohamnag - Mon, 2008-12-22 15:14

I think you are right Sven, I have just established a 4 language site. in such a site I prefer that when one menu item is added and linked to a page and that page is translated to other languages, the menu item automatically convert its link to translated pages when viewed in other languages than the original language. It's greate and much more better to force the site maintainer to make 4 different menu items for one page and its translations.


This is what needs to happen. Any luck with a solution?

milos1234-gdo - Mon, 2009-03-02 19:08

Hi,
Am trying my luck with i18n. Is there any progress on this solution? I really would like to install my site this way. What are the alternatives?
Many thanks


Is there any updates on this solution?

deepkey - Tue, 2009-04-21 16:05

Hi,

I've tried the last stable release of i18n for Drupal 6.
The is not solution for this issue yet.

Any progress so far?
Maintaining 1 menu with multiple translation.

Thanks alot


I agree with your approach

miiimooo@drupal.org - Wed, 2009-05-20 17:55

I agree with your approach in principal. If you have a complex site using multiple menus is the way to go - though it's not very user friendly. It could be a good idea to actually limit the menu listing in hook_form_alter and a bit of javascript to automatically select the right menu and change depending on language selection. What I'd like to know is what your approach is when the menu also contains views and panels. AFAIR these are translated via content translation which makes it - once again - very confusing the average user.


Since I've started working

miiimooo@drupal.org - Fri, 2009-07-31 18:27

Since I've started working on a new multilingual site I've looked at different options for the menu problem. The i18n module still scares the bollocks out of me so here's my latest idea. Stick this into template.php and you can start translating menu items right away in the Translate Interface section - and all without i18n just using the core locale module.

<?php
function template_preprocess_page(&$vars, $hook) {
 
$current_language = $vars['language']->language ;
  foreach ( array(
'primary_links', 'secondary_links') as $menu_name ) {
    if (empty(
$vars[$menu_name])) {
      continue;
    }
    foreach (
$vars[$menu_name] as $menu_key => $menu_item ) {
     
$vars[$menu_name][$menu_key]['title'] = t($vars[$menu_name][$menu_key]['title']);
     
$vars[$menu_name][$menu_key]['description'] = t($vars[$menu_name][$menu_key]['description']);
    }
  }
}
?>

I know it looks too simple to work but then I've had a look at what core is trying to do and it almost seems to translate menu items but then it never does - does this code make sense to anyone?

http://api.drupal.org/api/function/_menu_item_localize/6


I have tried on your code,

jessicakoh - Tue, 2009-11-10 14:37

I have tried on your code, miiimooo. It does not work. Do you have any updates on this code?


Missuse of t()

Kars-T's picture
Kars-T - Tue, 2009-11-10 15:33

@miiimooo

Please read this:
http://groups.drupal.org/node/15177

You must not use t() this way! The variables given into t() have to be constants in english not variable strings in some language! Otherwise you will for example put german into english and than can't translate it anymore.

You should use the tt() funktion for this:
http://drupal.org/node/304002

And to get the correct node translation use:
http://api.drupal.org/api/function/translation_node_get_translations/6

--

Karsten "Kars-T" Frohwein - comm-press

XING