Syed Shah created DELTASPIKE-1415: ------------------------------------- Summary: Enum Constant Internationalization Key: DELTASPIKE-1415 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1415 Project: DeltaSpike Issue Type: Improvement Security Level: public (Regular issues) Components: I18n-Module Reporter: Syed Shah
It'd be great to map enum constants to internationalization messages in a cleaner way. The use case is so an enum can be used to define something which users will see: - The status or state response for an action, represented by an enum. - The names for enum values such as togglable features, or types of a particular action that can be taken. - Where users must specify a specific item from a list. The simplest examples would be to return the localized status message of an action: If a method can return the statuses: `ENTITY_NOT_FOUND`, `ENTRY_NOT_CHANGED`, `ENTRY_ADDED`, `ENTRY_UPDATED`. Then in `src/main/java/resources/org/example/myapp/EnumMessages.properties`: ```properties org.example.app.EntryUpdateStatus.ENTITY_NOT_FOUND=No data is being stored on this entity. org.example.app.EntryUpdateStatus.ENTRY_NOT_CHANGED=No change has resulted from your action. org.example.app.EntryUpdateStatus.ENTRY_ADDED=You've now explicitly set that value. org.example.app.EntryUpdateStatus.ENTRY_UPDATED=You've changed the setting. ``` An alternative example may be when naming toggles or some kind of categories. Suppose an enum with the values `COMMON`, `UNCOMMON`, `RARE`, `LEGENDARY`. **`src/main/java/resources/org/example/myapp/EnumMessages.properties`** ```properties org.example.app.Rarity.COMMON=Vanlig org.example.app.Rarity.UNCOMMON=Uvanlig org.example.app.Rarity.RARE=Skjelden org.example.app.Rarity.LEGENDARY=Legendarisk ``` Then when using the desired `@MessageBundle`, references of an `Enum` data type can instead be looked up against the `EnumMessages.properties` file, and if not found, fall back to the original `toString()` logic. -- This message was sent by Atlassian Jira (v8.3.4#803005)