Commit 1b8f44ae authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #5498 from eddumelendez/gh-5483

* pr/5498:
  Polish contribution
  Add useAlwaysMessageFormat configuration key
parents 7db9280b 1e0873c8
...@@ -80,6 +80,12 @@ public class MessageSourceAutoConfiguration { ...@@ -80,6 +80,12 @@ public class MessageSourceAutoConfiguration {
*/ */
private boolean fallbackToSystemLocale = true; private boolean fallbackToSystemLocale = true;
/**
* Set whether to always apply the MessageFormat rules, parsing even messages without
* arguments.
*/
private boolean alwaysUseMessageFormat = false;
@Bean @Bean
public MessageSource messageSource() { public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
...@@ -92,6 +98,7 @@ public class MessageSourceAutoConfiguration { ...@@ -92,6 +98,7 @@ public class MessageSourceAutoConfiguration {
} }
messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale); messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale);
messageSource.setCacheSeconds(this.cacheSeconds); messageSource.setCacheSeconds(this.cacheSeconds);
messageSource.setAlwaysUseMessageFormat(this.alwaysUseMessageFormat);
return messageSource; return messageSource;
} }
...@@ -127,6 +134,14 @@ public class MessageSourceAutoConfiguration { ...@@ -127,6 +134,14 @@ public class MessageSourceAutoConfiguration {
this.fallbackToSystemLocale = fallbackToSystemLocale; this.fallbackToSystemLocale = fallbackToSystemLocale;
} }
public boolean isAlwaysUseMessageFormat() {
return this.alwaysUseMessageFormat;
}
public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat) {
this.alwaysUseMessageFormat = alwaysUseMessageFormat;
}
protected static class ResourceBundleCondition extends SpringBootCondition { protected static class ResourceBundleCondition extends SpringBootCondition {
private static ConcurrentReferenceHashMap<String, ConditionOutcome> cache = new ConcurrentReferenceHashMap<String, ConditionOutcome>(); private static ConcurrentReferenceHashMap<String, ConditionOutcome> cache = new ConcurrentReferenceHashMap<String, ConditionOutcome>();
......
...@@ -116,6 +116,21 @@ public class MessageSourceAutoConfigurationTests { ...@@ -116,6 +116,21 @@ public class MessageSourceAutoConfigurationTests {
.isFallbackToSystemLocale()).isFalse(); .isFallbackToSystemLocale()).isFalse();
} }
@Test
public void testFormatMessageDefault() throws Exception {
load("spring.messages.basename:test/messages");
assertThat(this.context.getBean(MessageSourceAutoConfiguration.class)
.isAlwaysUseMessageFormat()).isFalse();
}
@Test
public void testFormatMessageOn() throws Exception {
load("spring.messages.basename:test/messages",
"spring.messages.always-use-message-format:true");
assertThat(this.context.getBean(MessageSourceAutoConfiguration.class)
.isAlwaysUseMessageFormat()).isTrue();
}
@Test @Test
public void existingMessageSourceIsPreferred() { public void existingMessageSourceIsPreferred() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
......
...@@ -109,6 +109,7 @@ content into your application; rather pick only the properties that you need. ...@@ -109,6 +109,7 @@ content into your application; rather pick only the properties that you need.
spring.mandatory-file-encoding= # Expected character encoding the application must use. spring.mandatory-file-encoding= # Expected character encoding the application must use.
# INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration]) # INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration])
spring.messages.always-use-message-format=false # Set whether to always apply the MessageFormat rules, parsing even messages without arguments.
spring.messages.basename=messages # Comma-separated list of basenames, each following the ResourceBundle convention. spring.messages.basename=messages # Comma-separated list of basenames, each following the ResourceBundle convention.
spring.messages.cache-seconds=-1 # Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles are cached forever. spring.messages.cache-seconds=-1 # Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles are cached forever.
spring.messages.encoding=UTF-8 # Message bundles encoding. spring.messages.encoding=UTF-8 # Message bundles encoding.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment