デフォルトのロケールを日本語、その他サポートする言語を英語にしてみる。
<application> ・・・ <locale-config> <default-locale>ja</default-locale> <supported-locale>en</supported-locale> </locale-config> </application>
画面に表示されるボタンの名称などを国際化対応にする。
例)FormResources_ja.properties (native2asciiコマンドなどでUnicodeエスケープ・シーケンスに変換する必要がある。)
executeButton=実行
例)FormResources_en.properties
executeButton=Execute
<f:view> <f:loadBundle basename="FormResources" var="bundle"/> ・・・
<h:commandButton value="#{bundle.executeButton}" action="#{data1Bean.doSomething }"></h:commandButton>
エラーなどで使用するメッセージを国際化対応にする。
例)MessageResources_ja.properties (native2asciiコマンドなどでUnicodeエスケープ・シーケンスに変換する必要がある。)
myPackage.MyConverter.CONVERSION=変換エラーが発生しました。
例)MessageResources_en.properties
myPackage.MyConverter.CONVERSION=Conversion error occurred.
<application> ・・・ <message-bundle>MessageResources</message-bundle> ・・・ </application>
FacesContext ctx = FacesContext.getCurrentInstance(); Application app = ctx.getApplication(); UIViewRoot uivRoot = ctx.getViewRoot(); String messageBundle = app.getMessageBundle(); Locale locale = uivRoot.getLocale(); ResourceBundle rb = ResourceBundle.getBundle(messageBundle , locale); String message = rb.getString("myPackage.MyConverter.CONVERSION"));
IEの場合
Firefoxの場合
<f:view locale="en">
FacesContext ctx = FacesContext.getCurrentInstance(); ctx.getViewRoot().setLocale(new Locale("en"));