Skip to content

Commit

Permalink
Fix locale handling for search (#21)
Browse files Browse the repository at this point in the history
* Fix locale handling for search

* Update BeanConfig.java
  • Loading branch information
garamb1 authored Jul 1, 2024
1 parent 170ec3f commit aa04588
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Locale;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.validator.routines.UrlValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -13,6 +14,7 @@
import org.thymeleaf.spring6.SpringTemplateEngine;
import org.thymeleaf.spring6.view.ThymeleafViewResolver;

@Slf4j
@Configuration
@EnableScheduling
public class BeanConfig {
Expand All @@ -39,8 +41,9 @@ public ApplicationSettings applicationSettings(

@Bean
public SearchSettings searchSettings(
@Value("${retrosearch.search.locales:}") List<String> localeList) {
@Value("${retrosearch.search.locales}") List<String> localeList) {
List<Locale> locales = localeList.stream().map(StringUtils::parseLocaleString).toList();
log.info("Initialising search locales: {}", locales);
return new SearchSettings(locales);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ server.compression.enabled=true
server.error.whitelabel.enabled=false
retrosearch.encoding=UTF-8
retrosearch.html.version=3.2
retrosearch.search.locales=${SEARCH_LOCALES:en_US,en_GB,it_IT,de_DE}
retrosearch.search.locales=${SEARCH_LOCALES:en_US,en_GB,it_IT,de_DE,fr_FR,es_ES}
retrosearch.news.enable=${NEWS_ACTIVE:false}
retrosearch.news.api.key=${NEWS_API_KEY:}
retrosearch.news.api.rate.limiter=${NEWS_API_RATE_LIMITER:3000}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/fragments/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ <h4>
Search Query:
<input type="text" th:value="${searchResults?.query}" name="query">

<th:block th:unless="${#lists.isEmpty(@newsSettings.getLocales())}">
<th:block th:unless="${#lists.isEmpty(@searchSettings.getLocales())}">
<select name="locale">
<option th:each="locale: ${@newsSettings.getLocales()}"
<option th:each="locale: ${@searchSettings.getLocales()}"
th:text="${locale.getDisplayCountry()}"
th:value="${locale.toString()}"
th:selected="${searchResults?.locale == locale.toString()}">
Expand Down

0 comments on commit aa04588

Please sign in to comment.