grailsinternationalizationgrails-2.3

Repetitive method name/signature for method compilation error when using @I18nFields


I get repetitive method name/Signature compilation failure when i try to use i18nFields in my domain class to support multiple languages.

Grails Version : 2.3.7 ( I tried with 2.3.4 and got the same issue and upgraded)

Documentation from Grails followed for this was http://grails.org/plugin/i18n-fields

My Domain class looks like

package com.sampleapp.domain

import i18nfields.I18nFields;

@I18nFields
class Products {

 def name

 static constraints = {}

 static i18nFields = ['name']
}

My Config.groovy has the below line included to specify the locale

// internationalization support - testing 
i18nFields {
    locales = ['en','es']
}

BuildConfig.groovy plugin definition

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

The compilation error is

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.

The Error is repeated for the name property for both en and es locales twice.

There is no error if i remove the i18nFields annotation and the sample app worked fine before this. I verified GGTS repetitive method name/signature error in controllers post for similar error in controller. I have also verified to ensure that groovy version is correct and in my case it is 2.1

Can somebody please give me any pointers on where i should look to resolve this issue.


Solution

  • Probably it has something to do with the new Binding mechanism in grails 2.3. Maybe the getters and setters are set automatic now?

    When I comment out these two lines in ClassI18nalizator.groovy the error disappears. It seems to work at least partly. I can use the fields in scaffolding. It's not a real solution but maybe a hint for someone who understands grails better than me.

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

    After that I run into a second issue:

    No signature of method: groovy.util.ConfigObject.contain() is applicable for argument types: (java.lang.String) values: [en_US]

    I solved it by adding redisLocale to Config.groovy

    i18nFields { 
        locales = ['de_DE', 'en_US']
        defaultLocale = "en_US"
        redisLocales = ['de_DE', 'en_US']
    }