1

I'm working on a site with 34+ languages and will likely be expanding to more. With this many countries, a simple drop-down list can be difficult for usability. I would like to customize the language switcher so that I can categorize a language by region and country. I have seen this before, have created similar on other non-Drupal sites, but haven't seen anything like it for Drupal.

Example:

  • Europe
    • Germany
      • DE
    • Switzerland
      • DE
      • FR

etc.

I'm looking for either a module, or a head start on what I might do short of writing some custom PHP for the project.

0

You can take a clue from below modules..

Hierarchical Select module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.

enter image description here

Language Switcher Dropdown is a very simple module that exposes a new block, similar to the default Language Switcher block provided by Locale module. The new block allows site visitors to switch languages using a drop-down select list instead of using hyperlinks.

enter image description here

  • You need to build a custom module which displays region > countries using hierarchical select module
  • On Form Submit you need to do below actions which lang drop down does to redirect.

Please find submit handler code below from lang dropdown module..

function lang_dropdown_form_submit($form, &$form_state) {

  $language_code = check_plain($form_state['values']['lang_dropdown_select']);
  $type = $form_state['values']['lang_dropdown_type'];
  $tohome = $form_state['values']['lang_dropdown_tohome'];

  $language_codes = locale_language_list('language');
  if (!in_array($language_code, $language_codes)) return;

  $types = language_types_configurable(FALSE);
  if (!in_array($type, $types)) $type = 'language';

  $path = drupal_is_front_page() ? '<front>' : $_GET['q'];
  $languages = language_negotiation_get_switch_links($type, $path);

  $language = $languages->links[$language_code];

  $newpath = (isset($language['href']) && $tohome == 0) ? $language['href'] : '<front>';

  if (!isset($language['query'])) {
    $language['query'] = drupal_get_query_parameters();
  }

  $form_state['redirect'] = array($newpath, $language);

}

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.