Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Localizing Enums
Localizing Enums [message #893019] Mon, 02 July 2012 06:26 Go to previous message
Alexey Romanov is currently offline Alexey Romanov
Messages: 263
Registered: May 2010
Senior Member
While NLS class is nice to use, I sometimes want to localize messages corresponding to enums. Currently it looks like this in Java code:
package foo.bar;
public enum YesNo { YES, NO }

package foo.bar;
public class Msg extends NLS {
  public String yes;
  public String no;
  ... // other string fields
  
  static { /* init messages */ }

  public String getYesNoMsg(YesNo arg) {
    switch(arg) {
      case YES: return yes;
      case NO: return no;
    }
  }
}

and in properties file:
yes = ...
no = ...

So changing enum means I need to change 4 places:


  1. Enum itself
  2. Fields of Msg
  3. getYesNoMsg method
  4. properties file


Obviously, I can't get away from having to change 1 and 4, but ideally those should be the only places which have to change:
public enum YesNo { YES, NO }
package foo.bar;
public enum YesNo { YES, NO }

package foo.bar;
public class Msg extends NLS {
  public EnumMap<YesNo, String> yesNoMap;
  
  static { /* init messages */ }

  public String getYesNoMsg(YesNo arg) {
    return yesNoMap.get(arg)
  }
}

and in properties file:
foo.bar.YesNo.YES = ...
foo.bar.YesNo.NO = ...


The best I can do currently is 3 places to change: keep yes and no fields (renamed to foo_bar_YesNo_YES/NO), and fill EnumMap by reflection after initializing messages. Is there a better way that I missed?
 
Read Message
Read Message
Previous Topic:WorkbenchSourceProvider
Next Topic:app doesn't open any view nor editor after update to juno
Goto Forum:
  


Current Time: Sat May 25 16:38:31 EDT 2013

Powered by FUDForum. Page generated in 0.13343 seconds