Appending Language to Menu Items in Menu Admin (Drupal 7)
If you are working with a Drupal 7 menu that contains menu items across multiple languages it is a little cumbersome to see them all on the same screen. Right now we have all of the translations in place (3 nodes per piece of content), but we haven’t translated the titles yet. It’s very hard to see which items will appear for which languages. Imagine if we add 75 more menu items!
Here’s a quick snippet that will show the language beside each item. Note that it’s the language of the menu item itself, not the content that it points to.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/** * Implements hook_form_FORM_ID_alter(). */ function mymodule_form_menu_overview_form_alter(&$form, &$form_state, $form_id) { $languages = language_list(); // Append the language beside each menu item in the form foreach ($form as $key => $val) { if (strpos($key, 'mlid:') === 0 && $form[$key]['#item']['language'] != LANGUAGE_NONE) { $form[$key]['title']['#markup'] .= ' <em>' . $languages[$form[$key]['#item']['language']]->name . '</em>'; } } } |
Here’s the result. I translated (using Google Translate, so probably not too accurate) the Spanish items to show what that looks like: