开发者

How To Use I18N Messages In A Grails Plugin

开发者 https://www.devze.com 2023-03-17 05:52 出处:网络
I\'ve added a new exception to my plug开发者_开发技巧in: class UnzipException extends RuntimeException {

I've added a new exception to my plug开发者_开发技巧in:

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?


(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.

0

精彩评论

暂无评论...
验证码 换一张
取 消