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

Fix locale handling for search #21

Merged
merged 2 commits into from
Jul 1, 2024
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
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
Loading