Skip to content

Commit

Permalink
Facets filter labels not translated in result block (#10158)
Browse files Browse the repository at this point in the history
* indentation

* add comments et remove old "dead" code

* Add friendly name for value from filter query

* Add release note
  • Loading branch information
jeromeroucou authored Oct 4, 2024
1 parent 7be6c1b commit d50c484
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Fix facets filter labels not translated in result block

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.

This version of Dataverse fix this, and includes internationalization in the facets visible in the search results section.

For more information, see issue [#9408](https://github.com/IQSS/dataverse/issues/9408) and pull request [#10158](https://github.com/IQSS/dataverse/pull/10158)
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Logger;
Expand Down Expand Up @@ -1231,40 +1232,33 @@ public String getTypeFromFilterQuery(String filterQuery) {
}

public List<String> getFriendlyNamesFromFilterQuery(String filterQuery) {


if ((filterQuery == null)||
(datasetfieldFriendlyNamesBySolrField == null)||
(staticSolrFieldFriendlyNamesBySolrField==null)){

if ((filterQuery == null) ||
(datasetfieldFriendlyNamesBySolrField == null) ||
(staticSolrFieldFriendlyNamesBySolrField == null)) {
return null;
}
if(!filterQuery.contains(":")) {

if (!filterQuery.contains(":")) {
return null;
}

int index = filterQuery.indexOf(":");
String key = filterQuery.substring(0,index);
String value = filterQuery.substring(index+1);

List<String> friendlyNames = new ArrayList<>();
// friendlyNames get 2 entries : key and value
List<String> friendlyNames = new ArrayList<>(2);

// Get dataset field friendly name from default ressource bundle file
String datasetfieldFriendyName = datasetfieldFriendlyNamesBySolrField.get(key);
if (datasetfieldFriendyName != null) {
friendlyNames.add(datasetfieldFriendyName);
} else {
// Get non dataset field friendly name from "staticSearchFields" ressource bundle file
String nonDatasetSolrField = staticSolrFieldFriendlyNamesBySolrField.get(key);
if (nonDatasetSolrField != null) {
friendlyNames.add(nonDatasetSolrField);
} else if (key.equals(SearchFields.PUBLICATION_STATUS)) {
/**
* @todo Refactor this quick fix for
* https://github.com/IQSS/dataverse/issues/618 . We really need
* to get rid of all the reflection that's happening with
* solrQueryResponse.getStaticSolrFieldFriendlyNamesBySolrField()
* and
*/
friendlyNames.add("Publication Status");
} else {
// meh. better than nuthin'
friendlyNames.add(key);
Expand All @@ -1276,9 +1270,13 @@ public List<String> getFriendlyNamesFromFilterQuery(String filterQuery) {
String valueWithoutQuotes = noTrailingQuote;

if (key.equals(SearchFields.METADATA_TYPES) && getDataverse() != null && getDataverse().getMetadataBlockFacets() != null) {
Optional<String> friendlyName = getDataverse().getMetadataBlockFacets().stream().filter(block -> block.getMetadataBlock().getName().equals(valueWithoutQuotes)).findFirst().map(block -> block.getMetadataBlock().getLocaleDisplayFacet());
Optional<String> friendlyName = getDataverse().getMetadataBlockFacets()
.stream()
.filter(block -> block.getMetadataBlock().getName().equals(valueWithoutQuotes))
.findFirst()
.map(block -> block.getMetadataBlock().getLocaleDisplayFacet());
logger.fine(String.format("action=getFriendlyNamesFromFilterQuery key=%s value=%s friendlyName=%s", key, value, friendlyName));
if(friendlyName.isPresent()) {
if (friendlyName.isPresent()) {
friendlyNames.add(friendlyName.get());
return friendlyNames;
}
Expand All @@ -1290,7 +1288,15 @@ public List<String> getFriendlyNamesFromFilterQuery(String filterQuery) {
}
}

friendlyNames.add(valueWithoutQuotes);
// Get value friendly name from default ressource bundle file
String valueFriendlyName;
try {
valueFriendlyName = BundleUtil.getStringFromPropertyFile(noTrailingQuote, "Bundle");
} catch (MissingResourceException e) {
valueFriendlyName = noTrailingQuote;
}

friendlyNames.add(valueFriendlyName);
return friendlyNames;
}

Expand Down

0 comments on commit d50c484

Please sign in to comment.