Skip to content

Commit 22365ef

Browse files
committed
Merge branch '1.2.x' of github.com:grails/grails-core into 1.2.x
2 parents 69ba683 + 4530a70 commit 22365ef

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class I18nGrailsPlugin {
3939

4040
def doWithSpring = {
4141
// find i18n resource bundles and resolve basenames
42-
def baseNames = []
42+
def baseNames = [] as Set
4343

4444
def messageResources
4545
if(application.warDeployed) {
@@ -52,20 +52,25 @@ class I18nGrailsPlugin {
5252
if(messageResources) {
5353

5454
for( resource in messageResources) {
55-
// Skip files with a locale specification, since we assume
56-
// that there is an associated base resource bundle too.
57-
if (resource.filename.contains("_")) {
58-
continue
59-
}
60-
6155
// Extract the file path of the file's parent directory
6256
// that comes after "grails-app/i18n".
6357
def path = StringUtils.substringAfter(resource.path, baseDir)
6458

65-
// Lop off the extension - the "basenames" property in the
66-
// message source cannot have entries with an extension.
67-
path -= ".properties"
68-
59+
// look for an underscore in the file name (not the full path)
60+
def fileName = resource.filename
61+
def firstUnderscore = fileName.indexOf('_')
62+
63+
if(firstUnderscore > 0) {
64+
// grab everyting up to but not including
65+
// the first underscore in the file name
66+
def numberOfCharsToRemove = fileName.length() - firstUnderscore
67+
def lastCharacterToRetain = -1 * (numberOfCharsToRemove + 1)
68+
path = path[0..lastCharacterToRetain]
69+
} else {
70+
// Lop off the extension - the "basenames" property in the
71+
// message source cannot have entries with an extension.
72+
path -= ".properties"
73+
}
6974
baseNames << "WEB-INF/" + baseDir + path
7075
}
7176
}
@@ -124,3 +129,4 @@ class I18nGrailsPlugin {
124129
}
125130
}
126131
}
132+

src/test/org/codehaus/groovy/grails/plugins/i18n/I18nGrailsPluginTests.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ class I18nGrailsPluginTests extends AbstractGrailsMockTests {
1515

1616
ga.@applicationMeta = ['grails.war.deployed':'true'] as Metadata
1717
ctx.registerMockResource("WEB-INF/grails-app/i18n/messages.properties")
18+
ctx.registerMockResource("WEB-INF/grails-app/i18n/messages-site_en.properties")
19+
ctx.registerMockResource("WEB-INF/grails-app/i18n/foo-site_en.properties")
1820
ctx.registerMockResource("WEB-INF/grails-app/i18n/project.properties")
1921
ctx.registerMockResource("WEB-INF/grails-app/i18n/project_nl.properties")
22+
ctx.registerMockResource("WEB-INF/grails-app/i18n/sub/dir_name/sub/foo-bar_en.properties")
2023
ctx.registerMockResource("WEB-INF/grails-app/i18n/nobundle")
2124
ctx.registerMockResource("WEB-INF/grails-app/i18n/nobundle.txt")
2225
ctx.registerMockResource("WEB-INF/grails-app/i18n/nobundle.xml")
@@ -41,6 +44,9 @@ class I18nGrailsPluginTests extends AbstractGrailsMockTests {
4144
def messageSource = appCtx.getBean("messageSource")?.toString()
4245
println messageSource
4346
assert StringUtils.contains(messageSource, "messages")
47+
assert StringUtils.contains(messageSource, "messages-site")
48+
assert StringUtils.contains(messageSource, "foo-site")
49+
assert StringUtils.contains(messageSource, "foo-bar")
4450
assert StringUtils.contains(messageSource, "project")
4551
assert !StringUtils.contains(messageSource, "messages.properties")
4652
assert !StringUtils.contains(messageSource, "project.properties")

0 commit comments

Comments
 (0)