views:

119

answers:

1

I'm experiencing a strange issue with Ubuntu 10.04.1 LTS x86_64 where everything seems to work fine when the system locale is en_US. However, when the system locale is en_GB Spring tries to look for the default resource bundle as en_us rather than en_US.

The exception:

06-Oct-2010 23:35:12 org.springframework.context.support.ResourceBundleMessageSource getResourceBundle
WARNING: ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en_us

System Locale:

taylor@taylor-laptop:~$ locale
LANG=en_GB.utf8
LC_CTYPE="en_GB.utf8"
LC_NUMERIC="en_GB.utf8"
LC_TIME="en_GB.utf8"
LC_COLLATE="en_GB.utf8"
LC_MONETARY="en_GB.utf8"
LC_MESSAGES="en_GB.utf8"
LC_PAPER="en_GB.utf8"
LC_NAME="en_GB.utf8"
LC_ADDRESS="en_GB.utf8"
LC_TELEPHONE="en_GB.utf8"
LC_MEASUREMENT="en_GB.utf8"
LC_IDENTIFICATION="en_GB.utf8"
LC_ALL=
taylor@taylor-laptop:~$

The default Spring locale is setup like below:

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <property name="cookieName" value="USER_LOCALE" />
    <property name="cookieMaxAge" value="1209600" />
    <property name="defaultLocale" value="en_US" />
</bean>
+3  A: 

I've checked out the code from your github link above on an Ubuntu VM, and even with my locale changed to match yours:

matt@ubuntu-vm:~/google-app-engine-jappstart$ locale
LANG=en_GB.utf8
LANGUAGE=en_GB:en
LC_CTYPE="en_GB.utf8"
LC_NUMERIC="en_GB.utf8"
LC_TIME="en_GB.utf8"
LC_COLLATE="en_GB.utf8"
LC_MONETARY="en_GB.utf8"
LC_MESSAGES="en_GB.utf8"
LC_PAPER="en_GB.utf8"
LC_NAME="en_GB.utf8"
LC_ADDRESS="en_GB.utf8"
LC_TELEPHONE="en_GB.utf8"
LC_MEASUREMENT="en_GB.utf8"
LC_IDENTIFICATION="en_GB.utf8"
LC_ALL=

when I run mvn gae:run, I'm able to open up the index page of your webapp fine. I've even verified that if I print out the value of java.util.Locale.getDefault() from index.jsp, the value is en_GB.

Are you sure there are no other settings that you have that are causing this issue? Am I attempting to reproduce it incorrectly?

matt b
@matt - Thanks for the response. Actually, you won't see the error until you create an account and it tries to send an activation e-mail. Here's the link to the Google Code Issue: http://code.google.com/p/jappstart/issues/detail?id=3.
Taylor Leese
I get a different error: `org.springframework.context.NoSuchMessageException: No message found under code 'mail.subject' for locale 'en_us'.`. I'd suggest creating a default `messages.properties` for the MessageSource to fallback to when the current locale can't be resolved - if I copy your `messages_en_US.properties` to `messages.properties` and create an account, no error is generated. It is a good idea to supply a default ResourceBundle anyway, for any locales users might have (or choose) for which you don't have translated strings.
matt b
I think the bug is that your MailTask method is accepting a `@RequestParam String locale` as an argument. I'm not sure where this value is coming from - I don't see it passed it on the JSP. If you look at [the Spring docs](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-arguments), your handler can accept a `Locale` object as a parameter and Spring will automatically use your LocaleResolver to find the correct Locale to use - or your MailService should be looking up the Locale rather than having it passed in
matt b
@matt - That's not the problem. Take a look at RegisterController (http://github.com/tleese22/google-app-engine-jappstart/blob/master/src/main/java/com/jappstart/controller/RegisterController.java) and UserDetailsServiceImple (http://github.com/tleese22/google-app-engine-jappstart/blob/master/src/main/java/com/jappstart/service/auth/UserDetailsServiceImpl.java). I get the locale via "localeResolver.resolveLocale(request)" and then it's passed to the mail task. It receives the locale fine it's just that under the en_GB system locale it looks for en_us.properties rather than en_US.properties.
Taylor Leese
The real bug in my opinion is that Spring is trying to resolve en_us.properties rather than en_US.properties like it should. It resolves to en_US.properties in non-Ubuntu environments. I shouldn't have to create a messages.properties because en_US is set as the default locale in the localeResolver.
Taylor Leese
I guess I could just remove the default locale of en_US and move the en_US.properties to messages.properties. This would be a workaround, but I still don't understand why Spring is looking for en_us rather than en_US in Ubuntu.
Taylor Leese
Have you tried stepping through the code for `ResourceBundleMessageSource` and `AbstractMessageSource` in a debugger? This might illuminate where things are getting crossed. Either way I think it's a good idea to have a default bundle in case any client ever sets their locale to one you don't have a resourcebundle for.
matt b