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?

About these ads

4 thoughts on “Drupal – Translate Views Exposed Filter Label

  1. Ben Teegarden

    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!

    Reply
    1. ykyuen Post author

      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 -’ ?

      Reply
      1. ykyuen Post author

        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?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s