From c2d537191890db05b728cf311a8f604b22e40c5f Mon Sep 17 00:00:00 2001 From: Daniel Ellermann Date: Sat, 3 Jan 2015 12:01:14 +0100 Subject: [PATCH] Bugfix: i18n tag in production environment I fix a bug that i18n files were not found in production environment because they are searched in folder "grails-app/assets" instead of in folder "assets". Conflicts: I18nAssetPipelineGrailsPlugin.groovy grails-app/taglib/asset/pipeline/i18n/I18nTagLib.groovy src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy --- I18nAssetPipelineGrailsPlugin.groovy | 2 +- .../asset/pipeline/i18n/I18nTagLib.groovy | 31 +++++++++++++++++-- .../asset/pipeline/i18n/I18nAssetFile.groovy | 3 +- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/I18nAssetPipelineGrailsPlugin.groovy b/I18nAssetPipelineGrailsPlugin.groovy index dcbcab0..d409704 100644 --- a/I18nAssetPipelineGrailsPlugin.groovy +++ b/I18nAssetPipelineGrailsPlugin.groovy @@ -1,7 +1,7 @@ /* * I18nAssetPipelineGrailsPlugin.groovy * - * Copyright (c) 2014, Daniel Ellermann + * Copyright (c) 2014-2015, Daniel Ellermann * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/grails-app/taglib/asset/pipeline/i18n/I18nTagLib.groovy b/grails-app/taglib/asset/pipeline/i18n/I18nTagLib.groovy index fda9f17..c1dcb73 100644 --- a/grails-app/taglib/asset/pipeline/i18n/I18nTagLib.groovy +++ b/grails-app/taglib/asset/pipeline/i18n/I18nTagLib.groovy @@ -22,6 +22,7 @@ package asset.pipeline.i18n import asset.pipeline.AssetFile import asset.pipeline.AssetHelper import org.codehaus.groovy.grails.commons.GrailsApplication +import org.springframework.core.io.Resource /** @@ -65,6 +66,9 @@ class I18nTagLib { } } locale = locale.replace('-', '_') + if (log.debugEnabled) { + log.debug "Retrieving i18n messages for locale ${locale}…" + } String name = attrs.remove('name') ?: 'messages' String [] parts = locale.split('_') @@ -76,12 +80,35 @@ class I18nTagLib { buf << '_' << parts[j] } String s = buf.toString() - AssetFile f = AssetHelper.fileForUri(s, 'application/javascript') - if (f != null) { + if (log.debugEnabled) { + log.debug "Trying to find asset ${s}…" + } + + /* + * XXX This is a somewhat dirty hack. When running in WAR file a + * filter (asset.pipeline.AssetPipelineFilter) looks for a resource + * in folder "assets". So we try this first, and, if not found, we + * look in "grails-app/assets" via fileForUri(). + */ + Resource res = + grailsApplication.mainContext.getResource("assets/${s}.js") + if (res.exists()) { src = s + break + } else { + AssetFile f = + AssetHelper.fileForUri(s, 'application/javascript') + if (f != null) { + src = s + break + } } } + if (log.debugEnabled) { + log.debug "Found asset ${src ?: name}" + } out << asset.javascript(src: src ?: name) } } + diff --git a/src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy b/src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy index e30a808..7aded70 100644 --- a/src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy +++ b/src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy @@ -1,7 +1,7 @@ /* * I18nAssetFile.groovy * - * Copyright (c) 2014, Daniel Ellermann + * Copyright (c) 2014-2015, Daniel Ellermann * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,3 +89,4 @@ class I18nAssetFile extends AbstractAssetFile { fileText } } +