Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow defining localeResolver in Configuration #12471

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions grails-plugin-i18n/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
dependencies {
api project(":grails-web")

annotationProcessor "io.micronaut:micronaut-inject-java:$micronautVersion"
annotationProcessor "io.micronaut.spring:micronaut-spring-boot-annotation:$micronautSpringVersion"
compileOnly "io.micronaut:micronaut-inject-java:$micronautVersion"
compileOnly "io.micronaut.spring:micronaut-spring-annotation:$micronautSpringVersion"

api("org.springframework.boot:spring-boot-autoconfigure:$springBootVersion")
api "org.codehaus.groovy:groovy-ant:$groovyVersion"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2004-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.grails.plugins.i18n;

import org.grails.web.i18n.ParamsAwareLocaleChangeInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.servlet.LocaleResolver;

/**
* Default locale configuration.
*
* @author Michael Yan
* @since 5.1
*/
@Configuration
public class DefaultLocaleConfiguration {

@Bean
@ConditionalOnMissingBean
public LocaleChangeInterceptor localeChangeInterceptor() {
ParamsAwareLocaleChangeInterceptor localeChangeInterceptor = new ParamsAwareLocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
return localeChangeInterceptor;
}

@Bean
@ConditionalOnMissingBean
public LocaleResolver localeResolver() {
return new SessionLocaleResolver();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ import grails.util.Environment
import grails.util.GrailsUtil
import groovy.util.logging.Slf4j
import org.grails.spring.context.support.PluginAwareResourceBundleMessageSource
import org.grails.web.i18n.ParamsAwareLocaleChangeInterceptor
import org.springframework.context.support.ReloadableResourceBundleMessageSource
import org.springframework.core.io.Resource
import org.springframework.web.servlet.i18n.SessionLocaleResolver

import java.nio.file.Files

Expand Down Expand Up @@ -59,12 +57,6 @@ class I18nGrailsPlugin extends Plugin {
}
defaultEncoding = encoding
}

localeChangeInterceptor(ParamsAwareLocaleChangeInterceptor) {
paramName = "lang"
}

localeResolver(SessionLocaleResolver)
}}

@Override
Expand Down