java - Should I override Enum.toString() to localize an enum's label? -


today, have style question: given following code, should overriding enum#tostring() present application user localized string or switch custom function (say, getlabel()) or there method achieve same effect?

i'm after staying dry here, hardcoding resource bundle prefix not option.

i have simple enum this:

public enum due_date {    start,    presented;     public string tostring() {        return dbresbundle.instance().getstring("due_date_lbl_" + name());    } } 

where dbresbundle resourcebundle implementation can access msg in jsf so:

<h:selectonemenu value="#{m.due_date}" id="due">   <f:selectitems value="#{duedates}" var="d"      itemlabel="#{msg['due_date_lbl_'.concat(d.name())]}" /> </h:selectonemenu> 

i'm using the enum in code (not jsf) context, don't utilize tostring() there.

i've ended method getmsgkey() on of enums does

return getclass().getsimplename() + "_" + name(); 

which internationalization of multiple enums (translation of enum values) without enumtranslator.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -