How should I implement a dropdown box which contains a list of items which need to be shown in different languages?
-
03-07-2019 - |
Question
I'm trying to design a form which contains a dropdown box containing a list of grocery item choices.
What criteria should I look at when trying to decide on whether to use a java enum or a lookup table? Also, I will need to plan ahead for i18n support for the dropdown strings.
Solution
Use a Property Resource Bundle. They are designed for situations like this where you have to add i18n support.
Remember to think about sorting/ordering. Will the list be shown in the same order for all languages? Or sorted alphabetically according to the locale?
OTHER TIPS
I try to minimize look-up tables and use enums and code as much as possible until there is some additional data attached to each item that would need to be persisted. Also I usually use keys in the enum that map to ResourceBundle strings in order to find the right translation.