Why and when to perform this task
Server programs typically create LocalizableTextFormatter instances that are sent to clients as the result of some operation; clients format the objects at the appropriate time. Less typically, client programs create LocalizableTextFormatter objects locally.Steps for this task
Example
The following code creates a LocalizableTextFormatter instance by using the default constructor and then sets the required localization values:
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 application that is requesting a localized message can specify the locale and time zone for which the message is to be formatted, or the application can use the default values set for the Java virtual machine.
For example, a GUI can enable users to select the language in which to display the interface. A default value must be set initially so that the GUI can be created properly when the application first starts, but users can then change the locale for the GUI to suit their needs. The following code shows how to change the locale used by an application based on the selection of a menu item:
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."
What to do next
Set optional localization values.