Is there any way to translate replacement_value in in advanced sort options, when you select "Combine sort order with sort by" ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

naiara’s picture

I've managed to do that by replacing line 428 in better_exposed_filters_exposed_form_plugin.inc:
$rewrite[$search] = $replace;
with:
$rewrite[$search] = t($replace);

But it takes always English as default language, so you have to specify the text for the replacement in english and then translate it to the language you want.
I guess it's easy to fix by passing more arguments to the t() function, however, this did the trick for me.

geek-merlin’s picture

Title: Translate replacement_value in sort options » Translate replacement_value in sort options and in filter options

Same problem with filter options, i dare to extend the issue as both are oneliners.

geek-merlin’s picture

Status: Active » Needs review
FileSize
1.48 KB

Patch flying in that fixes both translations.

@others: please test and set issue status to rtbc, so we can get this in.

mikeker’s picture

Status: Needs review » Needs work

This seems like a good idea, and I want BEF to be as I18N-friendly as possible, but I'm have some concerned about using t() on variables. The API docs warn against translating variables "unless the text that the variable holds has been passed through t() elsewhere."

Major caveat: I have essentially zero experience with I18N sites. To those that do: please educate me! :)

berliner’s picture

Status: Needs work » Needs review
FileSize
5.14 KB

This is my approach on this topic. The attached patch is only for the overridden sort options but should be expandable easily.
It uses i18n_string_translate() to translate a variable ($combine_rewrite) that is exposed using hook_i18n_string_info().

For a german example, the original options array could look like this:

[created ASC] => Beitragsdatum Aufsteigend
[created DESC] => Beitragsdatum Absteigend
[field_price_value ASC] => Preis Aufsteigend
[field_price_value DESC] => Preis Absteigend

The german translation of the variable should then be entered likes this:

[Beitragsdatum Absteigend] => Neue zuerst
[Beitragsdatum Aufsteigend] => Älteste zuerst
[Price Aufsteigend] => Niedriger Preis
[Price Absteigend] => Hoher Preis

For more information on translation of user entered strings see:
Translating user-defined strings
Using the i18n API from other modules

mikeker’s picture

Status: Needs review » Needs work

Thanks for the patch and the example of how i18n functionality works. Much appreciated!

+++ b/better_exposed_filters_exposed_form_plugin.inc
@@ -936,7 +948,6 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
-          $bef_add_js = TRUE;
+++ b/better_exposed_filters_exposed_form_plugin.inc
@@ -1084,7 +1095,6 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
-          $bef_add_js = TRUE;
+++ b/better_exposed_filters_exposed_form_plugin.inc
@@ -1102,6 +1112,7 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
+          $bef_add_js = TRUE;

These seems unrelated to the issue at hand.

berliner’s picture

Status: Needs work » Needs review
FileSize
3.92 KB

Right, my bad. I have removed the unrelated lines and updated the patch.

mikeker’s picture

My apologies for the delay getting back to this issue. Thank you for the updated patch @berliner, it's been committed.

As mentioned in #5, this only works for exposed sort rewrites. I'll add an issue to continue this work for other parts of the BEF settings form. Regardless, this is a great start.

mikeker’s picture

Issue summary: View changes
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mikeker’s picture

mikeker’s picture

A word of warning to those using this functionality: The code from this issue has largely been removed in favor of the approach in #2185077: Allow translations for all BEF settings. That fix allows all BEF settings strings to be translated without the dependency on the i18n_strings and i18n modules. This is not a reflection on the work done in this issue -- I appreciate your contributions! -- I feel fewer dependencies is better.

This means that translations for exposed sort rewrite options using the i18n_strings will no longer work in newer versions of BEF. I will be rolling out a new release of BEF in a few days. Please use care when updating your code!

I've started a handbook page outlining directions for translating BEF settings. Please feel free to edit/update it as needed.