By default, org.exoplatform.portal.application.localization.DefaultLocalePolicyService
which is an
implementation of LocalePolicy
is installed to provide the default behaviour. This, however, can
easily be extended and overridden. A completely new implementation can also be written from scratch.
DefaultLocalePolicyService
treats logged-in users slightly differently than anonymous users. Logged-in users have a profile that can contain
language preference, while anonymous users do not.
Here is an algorithm used for anonymous users.
An algorithm for anonymous users
Iterate over the
LocaleContextInfo
properties in the following order:
cookieLocales
sessionLocale
browserLocales
portalLocale
Get each property's value. If it is a collection, get the first value.
If the value is one of the supported locales, return it as a result.
If the value is not in the supported locales set, try to remove country information, and check if a language matching locale is in the list of supported locales. If so, return it as a result.
Otherwise, continue with the next property. If no supported locale is found, the locale is returned to
portalLocale
by default.
The algorithm for logged-in users is virtually the same except that the first
Locale
source checked is user's profile.
An algorithm for logged-in users
Iterate over the
LocaleContextInfo
properties in the following order:
userProfile
cookieLocales
sessionLocale
browserLocales
portalLocale
Do the next steps which are the same as for anonymous users.