i18n - synching up Struts and JSTL
As he did with Roller, Jaap van der Molen made some enhancements to AppFuse to fully support internationalization. He also translated all the existing keys to Dutch. What a guy, eh?!
After I installed this enhanced version of AppFuse, I noticed a few quirks. Namely that my default language was Dutch. To me, this meant that my browser's local must be Dutch. However, since it wasn't, I knew there had to be an issue. After a bit of Googling, I found my answer. It turns out that if you don't specify the language on your default properties file, JSTL won't pick it up - and it defaults to the first one with a language specified. This means that you must have ApplicationResources_en.properties instead of ApplicationResources.properties. Also, another quirk is that you need to synch up Struts locale-setting and JSTL's locale-setting. To do this, I added the following method to my ActionFilter.java class:
// keep JSTL and Struts Locale's in synch Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY); if (locale == null) { locale = request.getLocale(); } if (request.getParameter("locale") != null) { locale = new Locale(request.getParameter("locale")); } session.setAttribute(Globals.LOCALE_KEY, locale); Config.set(session, Config.FMT_LOCALE, locale);
Even with all these "hacks" - Mozilla and Safari handle this stuff differently on the Mac. Jaap says that everything works fine on Windows w/o these hacks, so maybe it's just an OS X thing. Regardless, to make things easier, I've added the ability for users to switch between languages by clicking on their language of choice.
There's nothing like adding a new feature to something you're about to demo! I'm on in 45 minutes - the butterflies are fluttering like mad...
Posted by Jason Carreira on April 15, 2004 at 06:46 PM MDT #
Now when you request a ResourceBundle for English ( _en suffix) the ResourceBundle code doesn't find a match and so next tries the JVM default, Dutch. There is a match for Dutch so that's what you get.
To get around this, add an empty file with the _en suffix. Now when the ResourceBundle searches for _en it gets a match. However, for each property that is not in the _en file, i.e., all of them, it falls through to the base file and you get English.
To summarize, if your JVM will ever run with the default locale not the same as the base file, and there is a translated file for that default, add an empty file with the suffix of the language of the base file. Note that for a ListResourceBundle the file is java and isn't actually empty but contains some minimal information described in the javadoc for ResourceBundle.
Posted by Bob Hanner on April 30, 2004 at 06:35 PM MDT #
Posted by Matt Raible on April 30, 2004 at 07:00 PM MDT #
Posted by Bjørn Stenfeldt on May 07, 2004 at 06:03 PM MDT #
Posted by 216.189.172.8 on December 05, 2004 at 11:57 PM MST #
Posted by Chris Pratt on September 13, 2006 at 08:18 PM MDT #
Posted by 220.225.70.2 on November 01, 2007 at 05:56 AM MDT #
Posted by mars on July 20, 2009 at 08:23 AM MDT #
What simple set the default locale?