Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.