You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "Syed Shah (Jira)" <ji...@apache.org> on 2020/08/31 07:41:00 UTC

[jira] [Commented] (DELTASPIKE-1415) Enum Constant Internationalization

    [ https://issues.apache.org/jira/browse/DELTASPIKE-1415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17187519#comment-17187519 ] 

Syed Shah commented on DELTASPIKE-1415:
---------------------------------------

I wanted to try PR this at some point, but I'm not 100% sure on the best approach yet. 
Especially as I'm unsure on how best to have type-safe parameter interpolation, when its possible different messages in the same enum set may have different numbers of interpolable parameters.

Figured I'd post it here to see if it's a viable idea in the first place or if this would be undesirable.

> 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
>            Priority: Minor
>
> 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)