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".

Conflicts:
	I18nAssetPipelineGrailsPlugin.groovy
	grails-app/taglib/asset/pipeline/i18n/I18nTagLib.groovy
	src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy
  • Loading branch information
dellermann committed Jan 3, 2015
1 parent a3a99e3 commit c2d5371
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion I18nAssetPipelineGrailsPlugin.groovy
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
31 changes: 29 additions & 2 deletions grails-app/taglib/asset/pipeline/i18n/I18nTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand Down Expand Up @@ -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('_')
Expand All @@ -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)
}
}

3 changes: 2 additions & 1 deletion src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -89,3 +89,4 @@ class I18nAssetFile extends AbstractAssetFile {
fileText
}
}

0 comments on commit c2d5371

Please # to comment.