Skip to content

Instantly share code, notes, and snippets.

@KacT9H
Created January 15, 2017 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KacT9H/0acc5acde8dd5c575421c1128b6f81cd to your computer and use it in GitHub Desktop.
Save KacT9H/0acc5acde8dd5c575421c1128b6f81cd to your computer and use it in GitHub Desktop.
class CustomLocaleResolver extends SessionLocaleResolver {
def springSecurityService = Holders.grailsApplication.mainContext.getBean('springSecurityService')
Locale resolveLocale(HttpServletRequest request) {
//getting locale from session
Locale locale = (Locale) WebUtils.getSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME)
if (!locale) {
if (springSecurityService.isLoggedIn()) {
def user = springSecurityService.getCurrentUser() as User
locale = user.locale ?: determineDefaultLocale(request)
//put user's locale to session
setLocale(request, null, locale)
} else {
locale = determineDefaultLocale(request)
}
}
return locale
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment