Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 !
Comments
Comment #1
DjebbZ CreditAttribution: DjebbZ commentedHere's my hint !
The good thing is that it will automatically set the language according the current language. And it works, just tested a few minutes ago :)
Comment #2
LarsKramer CreditAttribution: LarsKramer commentedThere is now another module which displays the language switcher as a drop-down: http://drupal.org/project/lang_dropdown
Is there any change these two modules could be joined? I like the other features of Consistent Language Interface module.
Comment #3
SKAUGHTd7: you can envoke that form's functionality (more of less) by:
d8: shameless promotion..
https://www.drupal.org/project/dropdown_language
Comment #4
apadernoI 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.