wood burning stoves 2.0*
The moose likes Servlets and the fly likes Best practice for i18n/locale selection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best practice for i18n/locale selection?" Watch "Best practice for i18n/locale selection?" New topic
Author

Best practice for i18n/locale selection?

Andreas Schildbach
Ranch Hand

Joined: Jan 22, 2003
Posts: 34
Hello everyone,
I want to add locale (language) selection to my Servlet/JSP-based web site and like to hear about any i18n best practices or pointers there.
Requirements:
- If the user visits for the first time, the Accept-Language header of the servlet request should be used for determining a default locale. The user can either keep that default or make another selection on the web page.
- If the user selects another locale, he does so be clicking on a link that is present on any page of the web site. This action should only switch the locale, not the user location on the site map. For example, if the user was reading a specific entry in the guestbook, he should continue reading that entry but the navigational controls should appear in the newly selected language.
- The selected locale should be persistant:
* If the user is logged in, the user selected locale should be stored and loaded from the user database.
* If the user is not logged in, the selected locale should be stored and loaded from the session context.
* If the client cannot handle sessions, it looks like there is no way to persist the locale.
- I want to make extensive use of the JSTL (Java Standard Tag Library) for localizing my web pages:
* <fmt:bundle> should work without prior initialization.
* A construct like <c:if test="${locale == 'xx'}"> should also work (is there any better alternative?).
- Of course, the implementation has to be robust, performant, scalable, ...
I'd like you to share any thoughts about how you would implement these requirements.
More specifically,
- would you implement a servlet filter that is invoked prior to any resource in the web application, persisting the locale? Do any standard implementations of such a filter exist?
- is it a good idea to create an action Servlet/JSP with a backurl for selecting the locale? (/locale_selection?locale=xx&backurl=<came from this page> The action servlet could do the necessary modifications and then silently redirect the user to the "backurl".
Regards,
Andreas
 
Don't get me started about those stupid light bulbs.
 
subject: Best practice for i18n/locale selection?