Search code examples
springlocalemessage

Is there a way to force locale on a given spring message?


<spring:message code="someMessageCode" />

This works with the user locale (browser locale). I have a need to force locale on a particular message. I can handle this with a scriplet but I was wondering if there is a way we can tell Spring to use a specific locale for a particular messsage.


Solution

  • I don't think it is possible with spring messages macro, but you can create a MessageSourceAccessor and use it.

    Ex:

    MessageSourceAccessor messageResolver = new MessageSourceAccessor(messageSource, locale);
    

    Pass it to freemarker, then in freemarker

    ${messageResolver.getMessage("someMessageCode")}