Question

Have some multiline strings that are presented to the user and stored as Heredocs. So rather than a 'normal' (Java) property file, a groovy-based one (see here) to be consumed by ConfigSlurper was used and works great. Sorry if this is a dumb question, but can that be easily internationalized? If so, can you outline how that is accomplished?

Était-ce utile?

La solution 2

As far as I know the ConfigSlurper does not have special support for i18n.
You may achieve it by using the leveraging its support for environments by creating an environment closure per locale. For example:

environments {
  english {
    sample {
      hello = "hello"
    }
  }
  spanish {
    sample {
      hello = "hola"
    }
  }
}

When creating the ConfigSlurper you will need to pass the desired language:

def config = new ConfigSlurper("spanish")

Autres conseils

My solution: In your ConfigSlurper you should store keys to the internalized strings. Inject messageSourceand localResolver in your controller/service, get key from your ConfigSlurper and find localized string in your i18n messages.property file. Example (not sure that code is correct, but it's the main idea):

def config = new ConfigSlurper().parse(new File('src/Config.groovy').toURL())

//localized string1 value
def msg = messageSource.getMessage(config.data1.string1, null, localeResolver.defaultLocale)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top