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
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."
What to do next
Set optional localization values.Related tasks
Generating localized text
Composing language-specific strings
Related reference
LocalizableTextFormatter class