当我尝试在域类中使用i18nFields支持多种语言时,我得到重复的方法名称/签名编译失败。
Grails版本:2.3.7(我尝试使用2.3.4并得到了相同的问题并进行了升级)
随后来自Grails的文档为http://grails.org/plugin/i18n-fields
我的Domain类看起来像
package com.sampleapp.domain
import i18nfields.I18nFields;
@I18nFields
class Products {
def name
static constraints = {}
static i18nFields = ['name']
}
我的
Config.groovy包含以下行以指定区域设置
// internationalization support - testing
i18nFields {
locales = ['en','es']
}
BuildConfig.groovy插件定义
plugins {
// plugins for the build system only
build ":tomcat:7.0.47"
// plugins for the compile step
compile ":scaffolding:2.0.1"
compile ':cache:1.1.1'
// plugins needed at runtime but not for compilation
runtime ":hibernate:3.6.10.6" // or":hibernate4:4.1.11"//
runtime ":database-migration:1.3.8"
runtime ":jquery:1.10.2.2"
// compile ":jquery-ui:1.10.2.2"
runtime ":resources:1.2.1"
// Uncomment these (or add new ones) to enable additional resources capabilities
runtime ":zipped-resources:1.0.1"
runtime ":cached-resources:1.1"
//runtime ":yui-minify-resources:0.1.5"
compile ':platform-core:1.0.RC6'
compile ":cache-headers:1.1.5"
runtime ':spring-security-core:2.0-RC2'
// internationalization
compile ":i18n-fields:0.8.1"
}
编译错误是
grails-workspace\Test\grails-app\domain\com\sampleapp\domain\Products.groovy: -1: Repetitive method name/signature for method 'void setName_es(java.lang.String)' in class 'com.sampleapp.domain.Products'.
@ line -1, column -1.
en和es语言环境的name属性都重复两次错误。
如果我删除了i18nFields批注,并且示例应用程序在此之前运行良好,则没有错误。我验证了 GGTS repetitive method name/signature error in controllers帖子是否存在 Controller 中的类似错误。我也已验证以确保groovy版本正确,在我的情况下为2.1
有人可以给我有关我应该在哪里解决该问题的任何指示。
请您参考如下方法:
可能与grails 2.3中的新Binding机制有关。也许现在将自动将 setter和getter 设置为自动?
当我在ClassI18nalizator.groovy中注释掉这两行时,错误消失了。它似乎至少部分起作用。我可以在脚手架中使用这些字段。这不是一个真正的解决方案,但可能给那些比我更了解grails的人一个提示。
private def getSetterMethod(field) {
// setter should return void. that's why the return statement.
//return new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.setValue(this, '${field}', value); return;").pop();
}
private def getGetterMethod(field) {
//new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.getValueOrDefault(this, '${field[0..-7]}', '${field[-5..-1]}')").pop();
}
之后,我遇到了第二个问题:
No signature of method: groovy.util.ConfigObject.contain() is applicable for argument types: (java.lang.String) values: [en_US]
我通过将redisLocale添加到Config.groovy解决了它
i18nFields {
locales = ['de_DE', 'en_US']
defaultLocale = "en_US"
redisLocales = ['de_DE', 'en_US']
}




