Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Best practice for i18n/locale selection?  RSS feed

Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!