-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed as not planned
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
Dmytro Nosan opened SPR-16614 and commented
Sometimes to localize some bean we have to use several sources. e.g.
MessageSource m1 = db.getTranslations()
MessageSource m2 = someService.getTranslations();and then we will use a custom method for localizing
private String translate(MessageSource m1, MessageSource m2, String code, Locale locale) {
try {
return m1.getMessage(code, null, locale);
} catch (NoSuchMessageException ex) {
return m2.getMessage(code, null, locale);
}
}But this method has several disadvantages:
- If m1 has (useCodeAsDefaultMessage) we will never get a message from m2.
- A lot of exceptions could be thrown
- What would we do, if we need one or more MessageSource(s)?
My idea is to create a new ComposedMessageSource class which should handle:
- Resolve message from both MessageSources
- Resolve situation when one of the MessageSources has a property useCodeAsDefaultMessage (we should find the best option for localization)
- Unnecessary exception generation
also, it would be great to have a utility class for composing MessageSources.
public abstract class MessageSources {
@Nullable
public static MessageSource compose(@Nullable MessageSource messageSource, @Nullable MessageSource parentMessageSource){
...
}Affects: 5.0.4
Attachments:
- ComposedMessageSource.java (4.30 kB)
- ComposedMessageSourceTests.java (5.75 kB)
- MessageSource.java (3.86 kB)
- MessageSources.java (1.28 kB)
- MessageSourcesTest.java (686 bytes)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply