|
Localization and Internationalization
An Introduction with Examples in Java |
|
Prof. David Bernstein |
| Computer Science Department |
| bernstdh@jmu.edu |
Locale
class
encapsulates language
(ISO 639),
a script or writing system
(ISO 15924),
a country or region
(ISO 3166),
and a variant
(IETF BCP47) like Canadian French or Swiss German
Strings_en_US.properties
CANCEL = Cancel FILE = File OPEN = Open
Strings_fr_FR.properties
CANCEL = Annuler FILE = Fichier OPEN = Ouvrir
// Declare and initialize a static attribute
public static final ResourceBundle STRINGS =
ResourceBundle.getBundle("calc.ui.Strings");
// Use the static attribute to create a JButton
JButton cancelButton = new JButton(STRINGS.getString("CANCEL"));
cancelButton.setActionCommand("CANCEL");
// Respond to an event
public void actionPerformed(ActionEvent evt)
{
String command = evt.getActionCommand();
if (ac.equals("CANCEL"))
{
// Respond appropriately
}
}
NumberFormat class has a
static getCurrencyInstance() class that
returns a NumberFormat object that will
format currency information in a locale-specific way