Perform this task to set localization values for strings in an application component.
import com.ibm.websphere.i18n.localizabletext.LocalizableException; import com.ibm.websphere.i18n.localizabletext.LocalizableTextFormatter; import java.util.Locale; public void drawAccountNumberGUI(String accountType) { ... LocalizableTextFormatter ltf = new LocalizableTextFormatter(); ltf.setPatternKey("accountNumber"); ltf.setResourceBundleName("BankingSample.BankingResources"); ltf.setApplicationName("BankingSample"); ... }
The line of code in boldface exploits default behavior of the Java platform. By default, the Java platform looks first for a subclass of java.util.ResourceBundle called BankingResources. When none is found, the Java platform looks for a valid properties file of the same name. In this continuing example, a properties file is found.
The application that is requesting a localized message can specify the locale and time zone for message formatting, or the application can use the default values set for the Java virtual machine.
import java.awt.event.ActionListener; import java.awt.event.ActionEvent; ... import java.util.Locale; public void actionPerformed(ActionEvent event) { String action = event.getActionCommand(); ... if (action.equals("en_us")) { applicationLocale = new Locale("en", "US"); ... } if (action.equals("de_de")) { applicationLocale = new Locale("de", "DE"); ... } if (action.equals("fr_fr")) { applicationLocale = new Locale("fr", "FR"); ... } ... }
For more information, see "Generating localized text".