spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.81k stars 38.18k forks source link

i18n message format type ResourceBundleMessageSource [SPR-152] #4884

Closed spring-projects-issues closed 20 years ago

spring-projects-issues commented 20 years ago

olorin opened SPR-152 and commented

Locale setting is not applied to type formatting in ResourceBundleMessageSource.getMessage()

message templates messages_nl: payroll.init=Toepassing geinitialiseerd door {0} op {1,date,long} messages_fr: payroll.init=Application initialisée par {0} le {1,date,long}

code snippet: log.log(Level.WARNING, ctx.getMessage("payroll.init",new Object[]{"Guy",new Date()},new Locale("nl","BE"))); log.log(Level.WARNING, ctx.getMessage("payroll.init",new Object[]{"Elio",new Date()},new Locale("fr","FR")));

output: WARNING: Toepassing geinitialiseerd door Guy op 1 juni 2004 WARNING: Application initialisée par Elio le 1 juni 2004

-> french message is selected correctly but date is dutch formatted.

Doing messages manually:

MessageFormat formatter = new MessageFormat("Application initialisée par {0} le {1,date,long}",new Locale("fr","FR"));
    log.log(Level.WARNING, formatter.format(new Object[]{"Louis",new Date()}));

output OK: WARNING: Application initialisée par Louis le 1 juin 2004

bug or am i missing something?

tnx,

jan


Affects: 1.0.1

spring-projects-issues commented 20 years ago

Juergen Hoeller commented

Indeed, this is a bug: The MessageSource implementations should use a MessageFormat for the given Locale, and also cache MessageFormats per Locale. Thanks for the report! Juergen