grails - 在Grails中本地化验证(错误)消息

标签 grails localization internationalization

我尝试本地化来自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.



但是我收到的消息是“属性[大小]必须为数字”,而不是“属性[或然大小]必须为数字”。

我无法本地化的消息如下:
  • 属性[{0}]必须为数字
  • 属性[{0}]必须是有效日期//在这种情况下,我不能使用g:datePicker

  • 我用其他域类添加了其他示例,这也无法正常工作
    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/

    相关文章:

    gwt - grails + gwt通过 Controller 处理请求

    grails - 对空关联使用Grails GORM标准

    c# - 根据一年中的时间使用适当的本地 DST 感知时区(例如 PST 或 PDT)格式化本地 DateTime

    ruby-on-rails - i18n 属性回退

    java - 为什么cookie中没有保存参数?

    javascript - JS 检查按下的按键是英语 i 还是土耳其语 i

    java - 在 Grails 应用程序中添加/修改域类后重新启动 terracotta

    spring - 编译期间发生 fatal error org.springframework.beans.factory.BeanDefinitionStoreException

    php - 根据语言环境查找第一周和最后一周

    ios - 如何保持本地化 Storyboard 或 XIB 同步?