1

当我尝试i18nFields在我的域类中使用以支持多种语言时,我得到重复的方法名称/签名编译失败。

Grails 版本:2.3.7(我尝试使用 2.3.4 并遇到同样的问题并升级了)

来自 Grails 的文档是http://grails.org/plugin/i18n-fields

我的域类看起来像

package com.sampleapp.domain

import i18nfields.I18nFields;

@I18nFields
class Products {

 def name

 static constraints = {}

 static i18nFields = ['name']
}

MyConfig.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 重复方法名称/签名错误,以发现控制器中的类似错误。我还验证以确保 groovy 版本是正确的,在我的情况下它是 2.1

有人可以给我任何关于我应该在哪里解决这个问题的指示。

4

3 回答 3

10

当您尝试将 Java > v7 与任何版本的 Grails < 2.3.7 一起使用时,就会出现此问题。降级您的 jvm 或升级您的 grails。

于 2016-05-30T00:41:47.383 回答
1

感谢您的尝试(并通过 github 让我知道;))

这个问题是已知的,但尚未解决。先前的答案(注释掉方法)并不准确,尽管它遵循正确的轨道,因为问题来自 Grails 中的新更改,这将导致 getter 和 setter 发生冲突。

我找到的解决方案是分别创建属性和getter/setter,它似乎有效。

一旦可以在项目中进行全面测试,我就会发布一个新版本,但代码已经在https://github.com/jorgeuriarte/grails-i18n-fields-plugin/tree/redis_integration(版本 0.9- redis-SNAPSHOT)以防你想使用它。

于 2014-03-31T15:22:42.053 回答
0

可能它与 grails 2.3 中的新 Binding 机制有关。也许现在 getter 和 setter 是自动设置的?

当我在 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();
    }

之后我遇到了第二个问题:

没有方法签名:groovy.util.ConfigObject.contain() 适用于参数类型:(java.lang.String) 值:[en_US]

我通过将 redisLocale 添加到 Config.groovy 来解决它

i18nFields { 
    locales = ['de_DE', 'en_US']
    defaultLocale = "en_US"
    redisLocales = ['de_DE', 'en_US']
}
于 2014-03-23T18:22:56.063 回答