spring-projects / spring-projects/spring-framework
Support resolving messages with named arguments in MessageSource (java.util.Map)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
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}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the MessageSource interface and its existing implementations, then review the proposal's named-argument and delegation alternatives. Define the supported API, default unsupported behavior, implementation extension path, and documentation changes; done requires an agreed design and corresponding implementation coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, internationalization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100