Problem/Motivation
FilterPluginBase::groupForm potentially passes already translated values (via configuration translation through t() which can unnecessarily translate said values and insert unneeded strings into locale storage. The code segment below in /core/modules/views/src/Plugin/views/filter/FilterPluginBase.php is causing this issue.
foreach ($this->options['group_info']['group_items'] as $id => $group) {
if (!empty($group['title'])) {
$groups[$id] = $id != 'All' ? $this->t($group['title']) : $group['title'];
}
}
Steps to reproduce
- Create a view on a multilingual site that has at least one other language enabled
- Configuration translation and user interface translation should be enabled
- Set up a new view and a page display, add an exposed filter for a field that uses "Grouped filters", add some group items and add labels for them
- Access the view page in the non-default language, this will register the group item labels for user interface translation
- Translate the view + display via configuration translation and add unique language values for the group labels there
- Access the view page in the non-default language again, views will show the group item labels via configuration translation AND register them as new user interface strings to be translated.
Proposed resolution
Rely on configuration translation instead of string translation through t(). We can remove the conditional logic and revise it to:
foreach ($this->options['group_info']['group_items'] as $id => $group) {
if (!empty($group['title'])) {
$groups[$id] = $group['title'];
}
}
Issue fork drupal-3284983
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
lendudeEasily reproduced with the provided steps.
In light of #2972776: [policy, no patch] Better scoping for bug fix test coverage I'm marking this RTBC without test coverage.
Easy 1 line fix, no new code paths, complex to write tests for with little gain (it would only tests negatives, 'not translated double').
Comment #4
alexpottThere's probably more of this in views. Nice find!
I agree that testing for the absence of double translation is wrong.
Committed and pushed 80759ce855 to 10.1.x and 23d8da3938 to 10.0.x and 608eabd8e1 to 9.5.x. Thanks!
Will backport to 9.4.x once the branch is unfrozen.
Comment #8
alexpottCommitted 817b40b and pushed to 9.4.x. Thanks!