...
The following section loads the resource bundle for the supplied locale.
The locale parameter specifies the locale.
...
Code Block |
---|
public void setLocale(Locale locale) { this.locale = locale; System.out.println("Locale: " + this.locale.toString()); resBundle = ResourceBundle.getBundle("CETS", this.locale); } |
The following section returns the value from the resource bundle for the supplied key.
The The key parameter lookups the translation from the resource bundle and
returns and returns the value corresponding to the input key.
Code Block |
---|
...
public String getValue(String key) { String value = resBundle.getString(key); if (value == null) { value = ""; } return value; } |
...
Creating Property Files
Create separate property files for each locale the application supports as your resource bundles.
...
Code Block | ||||
---|---|---|---|---|
| ||||
<xal xmlns="http://openxal.org/ui/java"> <mco:mco xmlns:mco=http://openxal.org/core/mco id="i18nServiceRegistrar" src="com.nexaweb.i18n.utils.I18nServiceRegistrar" onLoad="mco:i18nServiceRegistrar.registerI18nService()"/> <mco:mco xmlns:mco="http://openxal.org/core/mco" id="sampleMco" src="com.nexaweb.i18nsample.mco.SampleMco" onLoad="mco:sampleMco.init()"/> <macro:macro xmlns:macro=http://openxal.org/core/macro name="repaintScreen"> <xm:modifications xmlns:xm="http://openxal.org/core/xmodify"> <xm:replace-children select="id(''presentationSpace'')"> <freePane xmlns="http://openxal.org/ui/java" width="1024px" height="768px"> <label height="20px" text="'{i18nService.getValue(''WELCOME_TEXT'')'}" width="200px" x="350px" y="30px" borderColor="#000000" borderWidth="1px"/> <label height="20px" text="'{i18nService.getValue(''USERID_TEXT'')'}" width="200px" x="120px" y="110px"/> <textField id="userId" height="25px" text="TextField" width="200px" x="320px" y="110px"/> <label height="20px" text="'{i18nService.getValue(''PASSWORD_TEXT'')'}" width="200px" x="120px" y="150px"/> <textField id="password" height="25px" text="TextField" width="200px" x="320px" y="150px"/> <button height="25px" text="'{i18nService.getValue(''CLEAR_TEXT'')'}" width="100px" x="320px" y="220px" onCommand="mco:sampleMco.clear()"/> <button height="25px" text="'{i18nService.getValue(''SUBMIT_TEXT'')'}" width="100px" x="430px" y="220px"/> </freePane> </xm:replace-children> </xm:modifications> </macro:macro> <rootPane> <borderPane> <horizontalFlowPane borderPosition="north" x="0px" y="0px" width="988px" height="40px" alignment="center"> <radioButton height="25px" text="US" width="100px" onSelect="mco:i18nServiceRegistrar.setLocale('en','US')" group="country" selected="true"/> <radioButton height="25px" text="Canada" width="100px" borderPosition="west" onSelect="mco:i18nServiceRegistrar.setLocale('fr','CA')" group="country"/> <radioButton height="25px" text="Mexico" width="100px" borderPosition="center" onSelect="mco:i18nServiceRegistrar.setLocale('sp','MX')" group="country"/> </horizontalFlowPane> <freePane id="presentationSpace" height="300px" width="300px" borderPosition="center" onCreate="macro:repaintScreen"/> </borderPane> </rootPane> </xal> |