Brad Rhoads
Brad Rhoads

Reputation: 1846

How To Use I18N Messages In A Grails Plugin

I've added a new exception to my plugin:

class UnzipException extends RuntimeException {
    String message
    String defaultMessage
    String fileName
}

. . .

        else {
            throw new UnzipException(
                message:"grailsant.unzipexception.badfile",
                defaultMessage: "Invalid zip file: ${zipFile}",
                fileName: zipFile)
        }
...

And in the plugin's messages.properties I have:

grailsant.unzipexception.badfile=Invalid zip file: {0}

Two questions:

  1. How do I get {0} filled in with fileName?

  2. Can an application override the grailsant.unzipexception.badfile message?

Upvotes: 0

Views: 1168

Answers (1)

Brad Rhoads
Brad Rhoads

Reputation: 1846

(1) It seems like this has to be done by app:

try {
  . . .
} catch (org.grails.plugins.grailsant.UnzipException e) {
     flash.message = e.message
     flash.args    = [e.fileName]
     flash.defaultMessage = e.defaultMessage
}

(2) Yep, if the message.properties in the app has the same key as the plugin, the app's values will be used.

Upvotes: 1

Related Questions