Language interface switcher : theme it as a drop-down list

Created on 18 April 2010, about 14 years ago
Updated 2 April 2023, over 1 year ago

Hello

I'm asking for a little help. I'd like to display the language switcher list as a drop-down list, so when the user selects a language he's automatically redirect, without a button to click. I got inspiration from this issue from i18n.

Here is the code I've put in template.php :

/**
 * Override of theme_languageswitcher()
 * Provided by languageinterface.module
 *
 * @param $links
 *   An array of all enabled languages links
 */
function zen_ninesixty_languageswitcher($links) {
  $output = '<form name="language-form">';
  $output .= '<select id="language-interface" onchange="window.location=document.language-form.language-interface.options[document.language-form.language-interface.selectedIndex].value;" value="GO">';
  foreach($links as $link) {
    $output .= '<option value="'. $link['path'] .'">';
    $output .= $link['text'];
    $output .= '</option>';
  }
  $output .= "</select>";
  $output .= "</form>";
  
  return $output;
}

The HTML output is correct, values and paths are properly populated. But nothing happens when I select a language... I tried 'onselect' instead of 'onchange', 'window.location.href' too, but nothing makes it...

Any hint really appreciated !

💬 Support request
Status

Closed: outdated

Version

2.5

Component

Miscellaneous

Created by

🇫🇷France DjebbZ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    I am closing this issue, since it is for a Drupal version that now is not supported.
    Please re-open it if the issue is also relevant for other project branches that require a supported Drupal version.

Production build 0.69.0 2024