JavaBlog.fr / Java.lu DEVELOPMENT,Java,Spring Spring: Problem with apostrophe (quote) in MessageSource

Spring: Problem with apostrophe (quote) in MessageSource

Hi,
After my post Spring: Internationalization with message source, I write a mini-post concerning a problem known in MessageSource of Spring for the message containing apostrophe or quote.

Indeed, there is a known issue (JIRA SPR-9169) in the Spring MessageSource component, a single apostrophe (or quote) is ignored and all text between quotes containing two parameters {1}, {2} is interpreted as plain text.

Example:
A simple Spring message source configuration in web application:
applicationContext.xml

<!-- ################### SPRING APPLICATION MESSAGES PROPERTIES ################### -->
<!-- Files concerned: -->
<!-- /WEB-INF/ApplicationMessageSource.properties -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
	<property name="defaultEncoding" value="UTF-8"/>
	<property name="basenames">
		<list>
			<value>classpath:ApplicationMessageSource</value>
		</list>
	</property>
</bean>

ApplicationMessageSource.properties

####### General messages ###########
alert.message=You don't have the permissions to {0} in {1}. Don't panic, your role is {2}!

-> In this case, the {0} and {1} parameters will be ignored, only, the parameter {2} will be replaced.

Solution: double the apostrophes in your messages

####### General messages ###########
alert.message=You don''t have the permissions to {0} in {1}. Don''t panic, your role is {2}!

Dear visitors, have you more efficient or intelligent solution?

That’s all!!!

Huseyin OZVEREN

3 thoughts on “Spring: Problem with apostrophe (quote) in MessageSource”

  1. I’m not that much of a online reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your website to come back in the future. Cheers

    1. Huseyin OZVEREN says:

      Thank you Basilia for your message. Kind regards.

  2. Peter Hazi says:

    Thanks, it works! 🙂

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

Related Post