A customer’s locale determines the language that the customer sees when viewing a site in Commerce Reference Store. This section describes how a customer’s locale is determined for each request.
Setting a customer’s locale is implemented through a series of includes. To start, an include-prelude
statement in the /WEB-INF/web.xml
file specifies that the store.war/includes/prelude.jspf
page fragment should be included for all Commerce Reference Store JSP pages. prelude.jspf
, in turn, includes the store.war/includes/context.jspf
page fragment. This fragment contains code for identifying and setting the customer’s locale and it looks like this:
<%-- Identify and set customer's locale --%> <dsp:importbean var="requestLocale" bean="/atg/dynamo/servlet/RequestLocale" /> <fmt:setLocale value="${requestLocale.locale}"/>
The context.jspf
fragment invokes the /atg/dynamo/servlet/RequestLocale
component included in the Store.EStore.International
module. RequestLocale
is of class atg.projects.store.servlet.StoreRequestLocale
, which extends the atg.userprofiling.ProfileRequestLocale
class with the following logic that determines a user’s locale:
First,
RequestLocale
determines if alocale
parameter is included in the HTTP request. Thelocale
parameter is embedded in the links associated with the language picker on thestore.war/navigation/gadgets/languages.jsp
gadget. When a customer clicks a language in the language picker, an appropriatelocale
is sent in the ensuing HTTP request. (See Rendering the Language Picker in the Multisite Features chapter for more details on the requests generated by the language picker.)If a
locale
is not present in the HTTP request,RequestLocale
looks to see if asiteId
is included in the request. If asiteId
is included,RequestLocale
uses the default locale for that site, as defined by thedefaultLanguage
property in the site’s configuration.If neither a
locale
nor asiteId
parameter is present in the HTTP request,RequestLocale
retrieves thelocale
from the customer’s profile.If a
locale
is not present in the customer’s profile,RequestLocale
retrieves thelocale
from the browser’suserPrefLanguage
cookie.If the
userPrefLanguage
cookie is not present,RequestLocale
uses the browser’s default locale.If the browser does not have a default locale,
RequestLocale
uses its own default setting, as specified by the optionaldefaultRequestLocale
property in theRequestLocale.properties
file.Finally, if
RequestLocale
doesn’t have a default setting, it uses the JVM’s locale default.
Once a locale is determined, RequestLocale
sets the locale
property in the customer’s profile and writes a userPrefLanguage
cookie to the browser that specifies the customer’s locale.
The context.jspf
page fragment also calls the fmt:setLocale
tag from the JavaServer Pages Standard Tag Library (JSTL). This tag sets the locale for any additional fmt
tags called for the remainder of the request, such as the fmt:message
tags that are used for displaying localized strings (see Displayable String Translations for more information).
Note: For more information on JTSL tags, see http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html.