Saturday, January 21, 2012

Determining a Customer’s Locale

A customer’s locale determines the language that the customer sees when viewing a site in CRS. 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 CRS 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 a locale parameter is included in the HTTP
request. The locale parameter is embedded in the links associated with the language
picker on the store.war/navigation/gadgets/languages.jsp gadget. When a
customer clicks a language in the language picker, an appropriate locale 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 a
siteId is included in the request. If a siteId is included, RequestLocale uses the
default locale for that site, as defined by the defaultLanguage property in the site’s
configuration.

· If neither a locale nor a siteId parameter is present in the HTTP request,
RequestLocale retrieves the locale from the customer’s profile.

· If a locale is not present in the customer’s profile, RequestLocale retrieves the
locale from the browser’s userPrefLanguage 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 optional defaultRequestLocale property in the
RequestLocale.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
Note: For more information on JTSL tags, see
http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html.

No comments:

Popular Posts