Skip to content

Commit

Permalink
Bugfix: i18n tag in production environment
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
dellermann committed Dec 20, 2014
1 parent 4cf4c07 commit d21d8a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion I18nAssetPipelineGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import asset.pipeline.i18n.I18nAssetFile


class I18nAssetPipelineGrailsPlugin {
def version = '0.9.0'
def version = '0.9.1'
def grailsVersion = '2.2 > *'
def title = 'I18n Asset Pipeline Plugin'
def author = 'Daniel Ellermann'
Expand Down
31 changes: 27 additions & 4 deletions grails-app/taglib/asset/pipeline/I18nTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package asset.pipeline

import org.codehaus.groovy.grails.commons.GrailsApplication
import org.springframework.core.io.Resource


class I18nTagLib {
Expand Down Expand Up @@ -56,6 +57,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('_')
Expand All @@ -67,13 +71,32 @@ class I18nTagLib {
buf << '_' << parts[j]
}
String s = buf.toString()
def f = AssetHelper.fileForUri(
s.toString(), '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 {
def 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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import asset.pipeline.CacheManager
* keys to localized messages.
*
* @author Daniel Ellermann
* @version 0.9.0
* @version 0.9
*/
class I18nAssetFile extends AbstractAssetFile {

Expand Down

0 comments on commit d21d8a5

Please # to comment.