How can I translate text inside controller in Spring Framework 3? How can I translate text inside controller in Spring Framework 3? spring spring

How can I translate text inside controller in Spring Framework 3?


If you are using annotated controllers you can autowire the MessageSource and add the locale of the request like this:

@Controller@Scope("request")public class MailController{    @Autowired    private MessageSource messageSource;    @RequestMapping(value = "/mail/send", method = RequestMethod.GET)    public ModelAndView sendEmail(Locale locale)    {        String[] args = { "Mr.", "X" };        // E.g. message.code="Dear {0} {1}"        String mailmessage = messageSource.getMessage("message.code", args, locale);        // Do something        return new ModelAndView();    }}