Without using Better Exposed Filters the translations for the 'Apply' and 'Reset' buttons work as expected by translating the strings using Translate interface. However if I select BEF for the form style the strings are not translated, the original string is displayed in all language versions of the site.

Comments

keszthelyi created an issue. See original summary.

vimokkhadipa’s picture

I have the same problem.

Baher’s picture

I have the same problem with button and the exposed field label

Baher’s picture

The same thing for me

DeonEmyr’s picture

Same issue for me too.

tsaks’s picture

Same issue.

ezoulou’s picture

same here

francoisb’s picture

I fixed this issue with PHP code, by implementing hook_form_alter() in a custom module:

function mymodule_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
  # Workaround bug "Button values not translated"
  # See: https://www.drupal.org/node/2565779
  $form['submit']['#value'] = t($form['submit']['#value']);
}

… where mymodule must be replaced by your module name.

kamenrs’s picture

I have the same issue, not only with Submit and Reset buttons, but also with the Secondary options label in BEF settings.
Is this bugfix going to be implemented in a dev or new version of the module?
Thanks.

mikeker’s picture

Sorry, my (limited) time right now is focused on getting an 8.x release out the door. I'm happy to commit quality patches that reviewed by the community in the 7.x branch. But until I have more time (or sponsorship) I can't put much effort into this branch.

Yannick Perret’s picture

Thanks to @francoisb for its workaround. Two notes:

  • you need to also add $form['reset']['#value'] = t($form['reset']['#value']); to also handle the reset button
  • if you use "autosubmit" the translated value is in "ajax", and ajax considers that 'en' is the default language (whatever your default language is), so if your default language is not english you have to put english value in the label and to translate it in your language
francoisb’s picture

@yannick-perret 'reset' is needed provided that the Reset button is actually displayed on the form. Settings allow for not displaying it, which is the case on my site. Code needs to first check presence of key $form['reset'], then do the translation.

Yannick Perret’s picture

I got an other problem: when translated, 'reset' button don't works anymore. The problem comes from 'views' code as far as I can see.
In views/plugins/views_plugin_exposed_form.inc (lien 296) reset is detected with $form_state['values']['op'] == $this->options['reset_button_label']. But when button label is translated, and because submit type in Drupal don't has a label part, here $form_state['values']['op'] contains the translated label but $this->options['reset_button_label'] contains the untranslated value. So it don't works.

I solved all by reset button problems (translation and working properly) by this two changes in views/plugins/views_plugin_exposed_form.inc:

Line 208
-        '#value' => $this->options['reset_button_label'],
+        '#value' => t($this->options['reset_button_label']),
Line 296
-    if (!empty($form_state['values']['op']) && $form_state['values']['op'] == $this->options['reset_button_label']) {
+    if (!empty($form_state['values']['op']) && $form_state['values']['op'] == t($this->options['reset_button_label'])) {

The first change ensure that the reset button is added with the translated label. The second change compares the 'value' part of the 'op' (which is translated) to the translated value of reset.

Of course I guess the same changes should be applied to submit button.

Some feedback? Do I need to submit an issue to 'views' module?

francoisb’s picture

@yannick-perret Yes, please. If your fix improves the views module, file issue there. Here you can suggest changes only for Better Exposed Filters.

Yannick Perret’s picture

Ok, I will do.
By the way I have a related issue with a very simple workaround for BEF: when replacing the "- Any -" label from BEF it is also not translated (and it is without BEF).

Comparing both codes seems to point to line 1728 in better_exposed_filters/better_exposed_filters_exposed_form_plugin.inc:

-        $form[$filter_id]['#options']['All'] = $options['more_options']['any_label'];
+        $form[$filter_id]['#options']['All'] = t($options['more_options']['any_label']);

At least this works for me.
I don't know if other cases are concerned (this is the only one I use).

I'm using BEF version 7.x-3.5 (datestamp = 1508952850).

Neslee Canil Pinto’s picture

Status: Active » Closed (won't fix)

Hi, there will be no more future development for 7.x branch. If you see this issue in 8.x, feel free to file an issue. Closing this as Closed(wont fix).