getting a list of all i18n properties used in a Grails application

You might know this situation: in a project you start by hacking code that uses i18n properties instead of fixed strings in order to support multiple languages. The normal process in Grails is to use the g:message tag in controllers or gsp templates. Side by side you append the new introduced i18n property with some value in your file.

When support for a new language is requested, all you have to do is translating So far so good – this make i18n really easy.

But: when the project evolves, there’s a good chance that some of your i18n properties in gets orphaned. Assume you remove a block of code from a gsp. It happens often that the i18n properties used in this block are not removed from messages*.properties because at some point you are not sure if it is referenced elsewhere. So what would be really useful here would be a list of all referenced i18n properties from your *.groovy/*.gsp files.

Doing so is pretty easy, just add a new gant script to your Grails application’s script folder, let’s name it i18nList.groovy. This script basically contains:

(sorry the color coding seems to fail for some Groovy regexes) The script recursivly iterates over all *.groovy and *.gsp files in your project and extract the part after the ‘code’ attribute of the message tag using a regex. The regex result are collected into an array. This array is sorted, unique’d and printed to the console. That’s it.

One word of caution: this gant script ‘works for me’. So depending on your code, you might notice that the used regex are not sufficient or even fail. Feel free to modify them for your needs, even better send back your modifications.

Join the Conversation


  1. @Stefan Armbruster
    Solution found, as our app uses snippets like ${message(code: foo.create’, default: ‘Create New’)} in GSP-Files we have to add the matcher for this to GSP case.

    switch (it) {
    case ~/.*\.groovy/:
    def matcher = it.text =~ /code:\s*[“‘](.*?)[“‘].*default:\s*[“‘](.*?)[“‘]/
    matcher.each { properties << it[1]+"="+it[2] }
    case ~/.*\.gsp/:
    def matcher = it.text =~ /code=["'](.*?)["'].*default=\s*["'](.*?)["']/
    matcher.each { properties << it[1]+"="+it[2] }
    def matcher2 = it.text =~ /code:\s*["'](.*?)["'].*default:\s*["'](.*?)["']/
    matcher2.each { properties << it[1]+"="+it[2] }

  2. Hi, i updated your scripts to match more possibilities:

    includeTargets < println “${k}=${v}” }



  3. Beware. Don’t use this script with the first line

    includeTargets << grailsScript("Init")

    This will reinitialize your application and rewrite changes you have already made

Leave a comment

Your email address will not be published. Required fields are marked *