Suppose you have two message files
messages.properties
messages_de.properties
Configuring application locales
There are three ways to install a Locale application, and I think you need the first one .
1 - You can allow the browser to select the locale.
Set the default values and supported locales to WEB-INF/faces-config.xml:
<faces-config>
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>de</supported-locale>
</locale-config>
</application>
</faces-config>
When a browser connects to your application, it usually includes the Accept-Language value in the HTTP header
2. .
setLocale UIViewRoot:
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
viewRoot.setLocale(new Locale("de"));
3 -
f:view locale, :
<f:view locale="de">
:
<f:view locale="#{user.locale}"/>
, Locale,
1-Via faces-config
- faces-config.xml WEB-INF :
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<resource-bundle>
<base-name>com.corejsf.messages</base-name>
<var>msgs</var>
</resource-bundle>
</application>
</faces-config>
2 - JSF, .
f: loadBundle JSF, , :
<f:loadBundle basename="com.corejsf.messages" var="msgs"/>
map msgs.
, i.e english
next=Next
i.e
next=Weiter
mesg, , ,
<h:commandButton value="#{msgs.next}"/>
Hortsmen Core Java Server Faces.