Skip to main content
added 121 characters in body
Source Link
SJuan76
  • 2.5k
  • 1
  • 18
  • 17

ResourceBundle is the way to go, but I would take advantage of the fact that enums are objects, and hide the details of i19n inside

public enum MyEnum { A, I, P; private String localeText = null; private MyEnum() { // Load resource bundle this.localeText = // get message; } public String getLocaleText() { return this.localeText(); } } 

That would allow you to do:

MyEnum.A.getLocaleText(); 

directly, everywhere

An optimization would be loading the resource bundle as an static attribute, in an static initializer.

And in JEE, bonus points for making the resource bundle injectable (so you may change the localization strings easily).

ResourceBundle is the way to go, but I would take advantage of the fact that enums are objects, and hide the details of i19n inside

public enum MyEnum { A, I, P; private String localeText = null; private MyEnum() { // Load resource bundle this.localeText = // get message; } public String getLocaleText() { return this.localeText(); } } 

That would allow you to do:

MyEnum.A.getLocaleText(); 

directly, everywhere

An optimization would be loading the resource bundle as an static attribute, in an static initializer.

ResourceBundle is the way to go, but I would take advantage of the fact that enums are objects, and hide the details of i19n inside

public enum MyEnum { A, I, P; private String localeText = null; private MyEnum() { // Load resource bundle this.localeText = // get message; } public String getLocaleText() { return this.localeText(); } } 

That would allow you to do:

MyEnum.A.getLocaleText(); 

directly, everywhere

An optimization would be loading the resource bundle as an static attribute, in an static initializer.

And in JEE, bonus points for making the resource bundle injectable (so you may change the localization strings easily).

Source Link
SJuan76
  • 2.5k
  • 1
  • 18
  • 17

ResourceBundle is the way to go, but I would take advantage of the fact that enums are objects, and hide the details of i19n inside

public enum MyEnum { A, I, P; private String localeText = null; private MyEnum() { // Load resource bundle this.localeText = // get message; } public String getLocaleText() { return this.localeText(); } } 

That would allow you to do:

MyEnum.A.getLocaleText(); 

directly, everywhere

An optimization would be loading the resource bundle as an static attribute, in an static initializer.