-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Overview
The MessageSource interface only supports positional arguments in messages. Alternative implementation with Map style argument have to create a parallel interface and implementation classes to support named arguments. Most i18n libraries I worked with in other ecosystem(non-Java) support named arguments. Unicode's new Message Format 2.0 doesn't event support positional arguments.
Proposal
Add additional methods to support named arguments in messages. The default implementation should throw UnsupportedOperationException. The documentation for MessageSource should indicate that an implementation could support either/both positional/named argument messages. Implementations will throw UnsupportedOperationException if they don't support it.
Additionally, offer a path to extend the existing MessageSource implementations with named argument support.
(Idea) Introduce an additional interface NamedMessageSoruce and make MessageSoruce extend it. All existing concrete classes should offer a way of delegating to NamedMessageSoruce. That way, you can support both positional(through the existing implementation) and named through delegation. Boot can later offer support for wiring such object.
Imaginary code:
@Bean
NamedMessageSoruceFactory namdMessageSoruceFactory() {
// custom impl here
}
// boot autowires NamedMessageSoruce into its MessageSource implementation to delegate the new methods
// application code
messageSoruce.getMessage("my_message", Map.of("date", ...), Locale.EN);
// messages.properties
my_message={$date :styel=short}