diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/InternationalizationConfiguration.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/InternationalizationConfiguration.java index 0064433fa..3dd0d131d 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/InternationalizationConfiguration.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/InternationalizationConfiguration.java @@ -6,12 +6,20 @@ import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.i18n.SessionLocaleResolver; +import java.util.Locale; + @Configuration public class InternationalizationConfiguration { @Bean public LocaleResolver localeResolver() { // TODO if we want to control the order, we can implement our own locale resolver instead of using the SessionLocaleResolver. SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver(); + + // NOTE: If we set a default here, Locale.getDefault's behavior will be consistent, but then Accept-Language + // is not honored (only ?lang=). If we do not set a default, the default is determined at runtime by the JVM. + // This may break unit tests if the system does not determine the default to be English. + // sessionLocaleResolver.setDefaultLocale(new Locale("en")); + return sessionLocaleResolver; } @@ -19,8 +27,9 @@ public LocaleResolver localeResolver() { public MappedResourceBundleMessageSource messageSource() { MappedResourceBundleMessageSource source = new MappedResourceBundleMessageSource(); source.setBasenames("i18n/messages"); - source.setUseCodeAsDefaultMessage(true); - source.setFallbackToSystemLocale(false); + source.setUseCodeAsDefaultMessage(false); //TODO Why was this true? + source.setFallbackToSystemLocale(false); // allows us to return messages.properties instead of + // messages_en.properties for unsupported languages. return source; } } diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesController.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesController.java index c5ec89f6c..b02c0df6d 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesController.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import javax.servlet.http.HttpServletRequest; import java.util.Collections; import java.util.HashSet; import java.util.Locale; diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesControllerTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesControllerTests.groovy index 722b929c8..9287ff552 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesControllerTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/InternationalizationMessagesControllerTests.groovy @@ -106,13 +106,23 @@ class InternationalizationMessagesControllerTests extends Specification { result.andExpect(content().json(expectedFrenchResult)) } - def "GET messages with an unsupported Accept-Language returns the default language"() { + def "GET messages with an unsupported Accept-Language returns the default (unspecified) language"() { when: def result = mockMvc.perform( get(messagesUrl) - .header("Accept-Language", "ja_JP")) + .header("Accept-Language", "ja")) then: - result.andExpect(content().json(expectedEnglishResult)) + result.andExpect(content().json(expectedDefaultResult)) + } + + def "GET messages with a made-up Accept-Language returns the default (unspecified) language"() { + when: + def result = mockMvc.perform( + get(messagesUrl) + .header("Accept-Language", "foo")) + + then: + result.andExpect(content().json(expectedDefaultResult)) } }