SeamFramework.orgCommunity Documentation
In a similar fashion to TimeZones we have an Application Locale
:
@Inject
private java.util.Locale lc;
accessible via EL with "defaultLocale".
By default the Locale
will be set to the JVM default, unless you
produce a String annotated with @DefaultLocale
. This can be achieved
through either the Seam Config module, with any bean that @Produces
a method or field that matches the type and qualifier.
This will set the application language to be English with the country of US:
@Produces
@DefaultLocale
private String defaultLocaleKey = "en_US";
As you can see from the previous example, you can define the Locale
with
lang_country_variant
. It's important to note that the first two parts of the locale definition
are not expected to be greater than 2 characters otherwise an error will be produced
and it will default to the JVM Locale
.
The Locale associated with the User Session can be retrieved by:
@Inject
@Client
private java.util.Locale locale;
which is EL accessible via userLocale
.
By default the Locale
will be that of the Application when the User Session
is initialized. However, changing the User's Locale
is a simple
matter of firing an event to update it. An example would be:
@Inject
@Client
@Alter
private Event<java.util.Locale> localeEvent;
public void setUserLocale() {
Locale canada = Locale.CANADA;
localeEvent.fire(canada);
}
We've also provided a list of available Locales that can be accessed via:
@Inject
private List<java.util.Locale> locales;
The locales that will be returned as available can be defined by extending LocaleConfiguration
.
As seen here:
public class CustomLocaleConfiguration extends LocaleConfiguration {
@PostConstruct
public void setup() {
addSupportedLocaleKey("en");
addSupportedLocaleKey("fr");
}
}