JMU
Localization and Internationalization
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Definitions
Common Requirements
Locales
Locales (cont.)
Techniques for Localizing Terminology
Working with Mapping
Working with Mappings (cont.)
Some Example Files

Strings_en_US.properties

CANCEL = Cancel
FILE = File
OPEN = Open

Strings_fr_FR.properties

CANCEL = Annuler
FILE = Fichier
OPEN = Ouvrir

Working with Mappings (cont.)
Using the Files
// 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
  }
}
  
Formatting Numbers
Formatting Currencies
Formatting Dates and Times
Formatting Dates and Times (cont.)
https://imgs.xkcd.com/comics/formatting_meeting.png
(Courtesy of xkcd)