aspose file tools
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best practice for i18n/locale selection?" Watch "Best practice for i18n/locale selection?" New topic

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.
- 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".
I agree. Here's the link:
subject: Best practice for i18n/locale selection?