Localizing enum values in resource bundle

后端 未结 5 736
借酒劲吻你
借酒劲吻你 2020-11-27 05:00

I have a problem with i18n enums in my JSF application. When I started, I had enums with the text defined inside. But now, I have keys tied to message bundles in the enum.

5条回答
  •  鱼传尺愫
    2020-11-27 05:25

    I calculate the message key in the enum like as shown below; so no need to maintain the keys with additional attributes on the enum

    public String getMessageKey() {
        return String.format("enum_%s_%s", this.getClass().getSimpleName(),
                this.name());
    }
    

    Then I use it like this

         
                
                
         
    

    with having configured a org.springframework.context.support.ReloadableResourceBundleMessageSource in the app context

    
        
        
        
    
    

提交回复
热议问题