Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facets filter labels not translated in result block #10158

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading