Skip to content

Commit a69d05f

Browse files
committed
Enable reloading also for (existing) i18n resource bundles if GSP reloading is enabled (GRAILS-5787 related).
1 parent 12d39c8 commit a69d05f

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/java/org/codehaus/groovy/grails/plugins/i18n/I18nGrailsPlugin.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import org.apache.commons.lang.StringUtils
2323
import org.apache.commons.logging.LogFactory
2424

2525
import org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource
26+
import org.codehaus.groovy.grails.web.context.GrailsConfigUtils;
2627
import org.codehaus.groovy.grails.web.i18n.ParamsAwareLocaleChangeInterceptor
28+
import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine
2729

2830
import org.springframework.core.io.ContextResource
2931
import org.springframework.context.support.ReloadableResourceBundleMessageSource
@@ -93,8 +95,13 @@ class I18nGrailsPlugin {
9395
basenames = baseNames.toArray()
9496
fallbackToSystemLocale = false
9597
pluginManager = manager
96-
if (Environment.current.isReloadEnabled()) {
97-
cacheSeconds = 5
98+
if (Environment.current.isReloadEnabled() || GrailsConfigUtils.isConfigTrue(application, GroovyPagesTemplateEngine.CONFIG_PROPERTY_GSP_ENABLE_RELOAD)) {
99+
def cacheSecondsSetting = application?.flatConfig?.get('grails.i18n.cache.seconds')
100+
if(cacheSecondsSetting != null) {
101+
cacheSeconds = cacheSecondsSetting as Integer
102+
} else {
103+
cacheSeconds = 5
104+
}
98105
}
99106
}
100107

src/java/org/codehaus/groovy/grails/plugins/web/GroovyPagesGrailsPlugin.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.codehaus.groovy.grails.commons.GrailsTagLibClass
2929
import org.codehaus.groovy.grails.commons.TagLibArtefactHandler
3030
import org.codehaus.groovy.grails.plugins.GrailsPluginManager
3131
import org.codehaus.groovy.grails.plugins.web.taglib.*
32+
import org.codehaus.groovy.grails.web.context.GrailsConfigUtils;
3233
import org.codehaus.groovy.grails.web.filters.JavascriptLibraryFilters
3334
import org.codehaus.groovy.grails.web.pages.*
3435
import org.codehaus.groovy.grails.web.pages.ext.jsp.TagLibraryResolver
@@ -91,8 +92,7 @@ class GroovyPagesGrailsPlugin {
9192
boolean developmentMode = !application.warDeployed
9293
Environment env = Environment.current
9394
boolean enableReload = env.isReloadEnabled() ||
94-
application?.flatConfig?.get(GroovyPagesTemplateEngine.CONFIG_PROPERTY_GSP_ENABLE_RELOAD) == true ||
95-
Boolean.getBoolean(GroovyPagesTemplateEngine.CONFIG_PROPERTY_GSP_ENABLE_RELOAD) ||
95+
GrailsConfigUtils.isConfigTrue(application, GroovyPagesTemplateEngine.CONFIG_PROPERTY_GSP_ENABLE_RELOAD) ||
9696
(developmentMode && env == Environment.DEVELOPMENT)
9797
boolean warDeployedWithReload = application.warDeployed && enableReload
9898
boolean enableCacheResources = !(application?.flatConfig?.get(GroovyPagesTemplateEngine.CONFIG_PROPERTY_DISABLE_CACHING_RESOURCES) == true)

src/java/org/codehaus/groovy/grails/web/context/GrailsConfigUtils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator;
2929
import org.codehaus.groovy.grails.plugins.GrailsPluginManager;
3030
import org.codehaus.groovy.grails.support.PersistenceContextInterceptor;
31+
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
3132
import org.springframework.beans.BeanUtils;
3233
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
3334
import org.springframework.context.ApplicationContext;
@@ -166,4 +167,22 @@ public static GrailsRuntimeConfigurator determineGrailsRuntimeConfiguratorFromSe
166167

167168
return configurator;
168169
}
170+
171+
/**
172+
* Checks if a Config parameter is true or a System property with the same name is true
173+
*
174+
*
175+
* @param application
176+
* @param propertyName
177+
* @return
178+
*/
179+
public static boolean isConfigTrue(GrailsApplication application, String propertyName) {
180+
return ((application != null && application.getFlatConfig() != null && DefaultTypeTransformation.castToBoolean(application.getFlatConfig().get(propertyName))) ||
181+
Boolean.getBoolean(propertyName));
182+
}
183+
184+
// support GrailsApplication mocking, see ControllersGrailsPluginTests
185+
public static boolean isConfigTrue(Object application, String propertyName) {
186+
return false;
187+
}
169188
}

0 commit comments

Comments
 (0)