Skip to content

Commit d50c484

Browse files
authored
Facets filter labels not translated in result block (#10158)
* indentation * add comments et remove old "dead" code * Add friendly name for value from filter query * Add release note
1 parent 7be6c1b commit d50c484

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Fix facets filter labels not translated in result block
2+
3+
On the main page, it's possible to filter results using search facets. If internationalization (i18n) has been activated in the Dataverse installation, allowing pages to be displayed in several languages, the facets are translated in the filter column. However, they aren't translated in the search results and remain in the default language, English.
4+
5+
This version of Dataverse fix this, and includes internationalization in the facets visible in the search results section.
6+
7+
For more information, see issue [#9408](https://github.com/IQSS/dataverse/issues/9408) and pull request [#10158](https://github.com/IQSS/dataverse/pull/10158)

src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java

+27-21
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.HashSet;
3535
import java.util.List;
3636
import java.util.Map;
37+
import java.util.MissingResourceException;
3738
import java.util.Optional;
3839
import java.util.Set;
3940
import java.util.logging.Logger;
@@ -1231,40 +1232,33 @@ public String getTypeFromFilterQuery(String filterQuery) {
12311232
}
12321233

12331234
public List<String> getFriendlyNamesFromFilterQuery(String filterQuery) {
1234-
1235-
1236-
if ((filterQuery == null)||
1237-
(datasetfieldFriendlyNamesBySolrField == null)||
1238-
(staticSolrFieldFriendlyNamesBySolrField==null)){
1235+
1236+
if ((filterQuery == null) ||
1237+
(datasetfieldFriendlyNamesBySolrField == null) ||
1238+
(staticSolrFieldFriendlyNamesBySolrField == null)) {
12391239
return null;
12401240
}
1241-
1242-
if(!filterQuery.contains(":")) {
1241+
1242+
if (!filterQuery.contains(":")) {
12431243
return null;
12441244
}
1245-
1245+
12461246
int index = filterQuery.indexOf(":");
12471247
String key = filterQuery.substring(0,index);
12481248
String value = filterQuery.substring(index+1);
12491249

1250-
List<String> friendlyNames = new ArrayList<>();
1250+
// friendlyNames get 2 entries : key and value
1251+
List<String> friendlyNames = new ArrayList<>(2);
12511252

1253+
// Get dataset field friendly name from default ressource bundle file
12521254
String datasetfieldFriendyName = datasetfieldFriendlyNamesBySolrField.get(key);
12531255
if (datasetfieldFriendyName != null) {
12541256
friendlyNames.add(datasetfieldFriendyName);
12551257
} else {
1258+
// Get non dataset field friendly name from "staticSearchFields" ressource bundle file
12561259
String nonDatasetSolrField = staticSolrFieldFriendlyNamesBySolrField.get(key);
12571260
if (nonDatasetSolrField != null) {
12581261
friendlyNames.add(nonDatasetSolrField);
1259-
} else if (key.equals(SearchFields.PUBLICATION_STATUS)) {
1260-
/**
1261-
* @todo Refactor this quick fix for
1262-
* https://github.com/IQSS/dataverse/issues/618 . We really need
1263-
* to get rid of all the reflection that's happening with
1264-
* solrQueryResponse.getStaticSolrFieldFriendlyNamesBySolrField()
1265-
* and
1266-
*/
1267-
friendlyNames.add("Publication Status");
12681262
} else {
12691263
// meh. better than nuthin'
12701264
friendlyNames.add(key);
@@ -1276,9 +1270,13 @@ public List<String> getFriendlyNamesFromFilterQuery(String filterQuery) {
12761270
String valueWithoutQuotes = noTrailingQuote;
12771271

12781272
if (key.equals(SearchFields.METADATA_TYPES) && getDataverse() != null && getDataverse().getMetadataBlockFacets() != null) {
1279-
Optional<String> friendlyName = getDataverse().getMetadataBlockFacets().stream().filter(block -> block.getMetadataBlock().getName().equals(valueWithoutQuotes)).findFirst().map(block -> block.getMetadataBlock().getLocaleDisplayFacet());
1273+
Optional<String> friendlyName = getDataverse().getMetadataBlockFacets()
1274+
.stream()
1275+
.filter(block -> block.getMetadataBlock().getName().equals(valueWithoutQuotes))
1276+
.findFirst()
1277+
.map(block -> block.getMetadataBlock().getLocaleDisplayFacet());
12801278
logger.fine(String.format("action=getFriendlyNamesFromFilterQuery key=%s value=%s friendlyName=%s", key, value, friendlyName));
1281-
if(friendlyName.isPresent()) {
1279+
if (friendlyName.isPresent()) {
12821280
friendlyNames.add(friendlyName.get());
12831281
return friendlyNames;
12841282
}
@@ -1290,7 +1288,15 @@ public List<String> getFriendlyNamesFromFilterQuery(String filterQuery) {
12901288
}
12911289
}
12921290

1293-
friendlyNames.add(valueWithoutQuotes);
1291+
// Get value friendly name from default ressource bundle file
1292+
String valueFriendlyName;
1293+
try {
1294+
valueFriendlyName = BundleUtil.getStringFromPropertyFile(noTrailingQuote, "Bundle");
1295+
} catch (MissingResourceException e) {
1296+
valueFriendlyName = noTrailingQuote;
1297+
}
1298+
1299+
friendlyNames.add(valueFriendlyName);
12941300
return friendlyNames;
12951301
}
12961302

0 commit comments

Comments
 (0)