我尝试本地化来自Domain类的错误消息。默认错误消息是可能的,例如:
default.blank.message=Property [{0}] cannot be blank
和本地化的属性名称,例如:
customer.address.label=Customer address
其中“客户”是我的域类,地址是它的属性。
我的问题是我无法本地化某些属性,因为我需要特定的错误消息。
例如:
has.to.be.a.number=Property [{0}] has to be a number
contingent.size.label=Contingent size.
但是我收到的消息是“属性[大小]必须为数字”,而不是“属性[或然大小]必须为数字”。
我无法本地化的消息如下:
我用其他域类添加了其他示例,这也无法正常工作
package cz.quanti.spaportal.touristOffice
import ...
class TouristOffice {
String customerNumber
int minimalContingent
Address address
User user
ContactPerson contactPerson
static hasMany = [contingents: Contingent]
static constraints = {
customerNumber(unique:true, nullable: true, blank: true)
user(nullable: true, blank: true)
contactPerson(nullable: false)
minimalContingent(min: 0)
address(nullable: false)
}
仅“minimalContingent”未本地化:(消息已本地化,minimum属性未定位)
属性[minimalContingent]必须为数字。
最佳答案
我认为该属性的整个路径(最后没有“label”)应该适合您。看起来像这样:
com.example.Customer.homeAddress=Customer address
请记住在需要时使用小写和大写字母!
关于grails - 在Grails中本地化验证(错误)消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4670784/