其中';s在Grails中找到了messageSource的声明? 背景

其中';s在Grails中找到了messageSource的声明? 背景,grails,internationalization,grails-2.0,Grails,Internationalization,Grails 2.0,对于存储在数据库中的字段标签,我们有一些传统的国际化,所以我尝试创建一个“合并”的messageSource。如果数据库中存在代码,请返回,如果不存在,请使用PluginAwareResourceBundleMessageSource查看i18n 问题 出于某种原因,cachedMergedPluginProperties正在为区域设置缓存错误的文件。例如,如果我搜索en_US,我会收到pt_BR消息(映射的键是en_US,但属性是pt_BR) 我声明我的messageSource如下: mes

对于存储在数据库中的字段标签,我们有一些传统的国际化,所以我尝试创建一个“合并”的messageSource。如果数据库中存在代码,请返回,如果不存在,请使用PluginAwareResourceBundleMessageSource查看i18n

问题 出于某种原因,cachedMergedPluginProperties正在为区域设置缓存错误的文件。例如,如果我搜索en_US,我会收到pt_BR消息(映射的键是en_US,但属性是pt_BR)

我声明我的messageSource如下:

messageSource(DatabaseMessageSource) {
  messageBundleMessageSource = { org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource m ->
    basenames = "WEB-INF/grails-app/i18n/messages"
    } 
}  
内部bean是因为Grails不会让我拥有两个
MessageSource
类型的bean


我声明的
PluginAwareResourceBundleMessageSource
是否与Grails的默认值不同?在哪个Grails文件中可以看到这个bean声明?

我在
I18nGrailsPlugin
中找到了该声明,它比我的声明更详细一些:

String baseDir = "grails-app/i18n"
String version = GrailsUtil.getGrailsVersion()
String watchedResources = "file:./${baseDir}/**/*.properties".toString()
...
 Set baseNames = []

        def messageResources
        if (application.warDeployed) {
            messageResources = parentCtx?.getResources("**/WEB-INF/${baseDir}/**/*.properties")?.toList()
        }
        else {
            messageResources = plugin.watchedResources
        }

        if (messageResources) {
            for (resource in messageResources) {
                // Extract the file path of the file's parent directory
                // that comes after "grails-app/i18n".
                String path
                if (resource instanceof ContextResource) {
                    path = StringUtils.substringAfter(resource.pathWithinContext, baseDir)
                }
                else {
                    path = StringUtils.substringAfter(resource.path, baseDir)
                }

                // look for an underscore in the file name (not the full path)
                String fileName = resource.filename
                int firstUnderscore = fileName.indexOf('_')

                if (firstUnderscore > 0) {
                    // grab everyting up to but not including
                    // the first underscore in the file name
                    int numberOfCharsToRemove = fileName.length() - firstUnderscore
                    int lastCharacterToRetain = -1 * (numberOfCharsToRemove + 1)
                    path = path[0..lastCharacterToRetain]
                }
                else {
                    // Lop off the extension - the "basenames" property in the
                    // message source cannot have entries with an extension.
                    path -= ".properties"
                }
                baseNames << "WEB-INF/" + baseDir + path
            }
        }

        LOG.debug "Creating messageSource with basenames: $baseNames"

        messageSource(PluginAwareResourceBundleMessageSource) {
            basenames = baseNames.toArray()
            fallbackToSystemLocale = false
            pluginManager = manager
            if (Environment.current.isReloadEnabled() || GrailsConfigUtils.isConfigTrue(application, GroovyPagesTemplateEngine.CONFIG_PROPERTY_GSP_ENABLE_RELOAD)) {
                def cacheSecondsSetting = application?.flatConfig?.get('grails.i18n.cache.seconds')
                if (cacheSecondsSetting != null) {
                    cacheSeconds = cacheSecondsSetting as Integer
                } else {
                    cacheSeconds = 5
                }
            }
        }
String baseDir=“grails app/i18n”
String version=GrailsUtil.getGrailsVersion()
String watchedResources=“file:./${baseDir}/***.properties”。toString()
...
设置基本名称=[]
def消息资源
如果(应用程序warDeployed){
messageResources=parentCtx?.getResources(“**/WEB-INF/${baseDir}/**.properties”)?.toList()
}
否则{
messageResources=plugin.watchedResources
}
if(messageResources){
for(messageResources中的资源){
//提取文件父目录的文件路径
//这是在“grails app/i18n”之后出现的。
字符串路径
if(ContextResource的资源实例){
path=StringUtils.substringAfter(resource.pathWithinContext,baseDir)
}
否则{
path=StringUtils.substringAfter(resource.path,baseDir)
}
//在文件名中查找下划线(不是完整路径)
字符串文件名=resource.fileName
int first下划线=fileName.indexOf(“”)
如果(第一下划线>0){
//抓取到但不包括的所有内容
//文件名中的第一个下划线
int numberOfCharsToRemove=fileName.length()-first下划线
int lastCharacterToRetain=-1*(numberOfCharsToRemove+1)
路径=路径[0..lastCharacterToRetain]
}
否则{
//删除扩展名-中的“basenames”属性
//消息源不能有扩展名为的条目。
路径-=“.properties”
}
基本名称