« Return to Thread: Change i18n locale from a controller before calling the view

Re: Change i18n locale from a controller before calling the view

by AleCaste :: Rate this Message:

Reply to Author | View in Thread

Hello guys,

I found the answer myself.
I want to post it here in case someone else has the same need in the future.
The controller code would look like this:


import org.springframework.web.servlet.support.RequestContextUtils as RCU
class myController {
  def index = {
    'Let's change the Locale to, let's say...  'es_ES'
    def newLocale = new Locale('es', 'ES')
    RCU.getLocaleResolver(request).setLocale(request, response, newLocale)
    'DONE! Now when the view is rendered, it'll be done using the new locale
  }
}

 « Return to Thread: Change i18n locale from a controller before calling the view