Drupal – Translate Views Exposed Filter Label

1. Go to <drupal>/admin/build/views/tools
 

2. Select – Any – for Label for “Any” value on optional single-select exposed filters:

 

3. Save and you can find – Any – in Translate interface.
 

If you don’t want to use – Any –, then you need to alter the form using hook_form_alter().

...
function <module>_form_alter(&$form, $form_state, $form_id) {
  if($form_state['view']->name == 'your_view_name_here') {
    // overrides <All> on the dropdown
    $form['your_dropdown_name']['#options']['All'] = t('- Type -');
  }
}

 

Done =)

Reference: StackOverflow – How to change the label of the default value (-Any-) of an exposed filter in Drupal Views?

4 thoughts on “Drupal – Translate Views Exposed Filter Label”

  1. All this is doing for me is adding another option ‘- Type -‘ in my dropdown filter. It does not translate ‘- Any – ‘, it leaves it untouched. Any ideas? Thanks!

    Like

    1. For an t() wrapped strings, you can add the translation thru the Translate Interface if you have installed the i18n module.

      Have you installed the i18n module and search for the string ‘- Type -’ ?

      Like

      1. That’s weird,.
        In that case, you could determine the current language in PHP and set the translated string direct in the hook_form_alter(). For example.

        ...
        function <module>_form_alter(&$form, $form_state, $form_id) {
          global $language;
          if($form_state['view']->name == 'your_view_name_here') {
            if ($language->language == 'en') {
              $form['your_dropdown_name']['#options']['All'] = t('- Type -');
            } else if if ($language->language == 'fr') {
              $form['your_dropdown_name']['#options']['All'] = t('- Genre -');
            }
          }
        }
        

        Does it help?

        Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.