Skip to content

Instantly share code, notes, and snippets.

@tamboer
Created December 18, 2017 15:02
Show Gist options
  • Select an option

  • Save tamboer/3a6b5e4ae6ce29e2ae7788b6ed0943d3 to your computer and use it in GitHub Desktop.

Select an option

Save tamboer/3a6b5e4ae6ce29e2ae7788b6ed0943d3 to your computer and use it in GitHub Desktop.
enum with translations
import com.tvh.assetmanagement.common.SupportedLocales;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public enum EngineType {
THERMAL("Thermal", "Thermisch"),
ELECTRICAL("Electrical", "Elektrisch"),
MANUAL("Manual", "Manueel");
private Map<Locale,String> descriptions = new HashMap<>();
EngineType(final String description, final String descriptionNL) {
this.descriptions.put(SupportedLocales.ENGLISH, description);
this.descriptions.put(SupportedLocales.DUTCH, descriptionNL);
}
public String getDescription() {
return descriptions.get(SupportedLocales.getDefault());
}
public String getDescription(Locale locale) {
return descriptions.get(locale);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment