Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there any way to translate replacement_value in in advanced sort options, when you select "Combine sort order with sort by" ?
Comment | File | Size | Author |
---|---|---|---|
#7 | better_exposed_filters-i18n-1670140-7.patch | 3.92 KB | berliner |
#5 | better_exposed_filters-i18n-1670140-5.patch | 5.14 KB | berliner |
#3 | 0001-Fixed-1670140-Added-Translate-replacement_value-in-s.patch | 1.48 KB | geek-merlin |
Comments
Comment #1
naiara CreditAttribution: naiara commentedI'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.
Comment #2
geek-merlinSame problem with filter options, i dare to extend the issue as both are oneliners.
Comment #3
geek-merlinPatch flying in that fixes both translations.
@others: please test and set issue status to rtbc, so we can get this in.
Comment #4
mikeker CreditAttribution: mikeker commentedThis 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! :)
Comment #5
berliner CreditAttribution: berliner commentedThis 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:
The german translation of the variable should then be entered likes this:
For more information on translation of user entered strings see:
Translating user-defined strings
Using the i18n API from other modules
Comment #6
mikeker CreditAttribution: mikeker commentedThanks for the patch and the example of how i18n functionality works. Much appreciated!
These seems unrelated to the issue at hand.
Comment #7
berliner CreditAttribution: berliner commentedRight, my bad. I have removed the unrelated lines and updated the patch.
Comment #8
mikeker CreditAttribution: mikeker commentedMy 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.
Comment #9
mikeker CreditAttribution: mikeker commentedComment #11
mikeker CreditAttribution: mikeker commentedComment #12
mikeker CreditAttribution: mikeker commentedA 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.