Created
January 15, 2017 11:05
-
-
Save KacT9H/0acc5acde8dd5c575421c1128b6f81cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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