JMU JMU - Department of Computer Science
Help Tools
Lab: Gaining Experience with Localization/Internationalization


Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.

Getting Ready: Before going any further, you should:

  1. Setup your development environment.
  2. This lab is a simulation of a part of the process that is being used to create a product named Wherez for the (hypothetical) company Nearby. The team is using an incremental process known as Scrum, which divides the work up into sprints.

    If you have not already done so, you must complete the lab on serialization before you can start this lab. If you have already completed the executable .jar files you should start with that version of the code instead.

  3. Read the sprintable stories.
  4. Read the course help page on Internationalization/Localization and/or the , lecture notes on the same topic.
  5. Briefly review the documentation for the ResourceBundle java.util.ResourceBundle and PropertyResourceBundle java.util.PropertyResourceBundle classes.

1. Tasks: The sprintable stories have been decomposed into the following tasks.
  1. Create a file named Strings_en_US.properties using the resource bundle format in the package wherez.gui. It must contain all of the String constants in the WherezController and WherezWindow classes. The name of the constant must be the key and the value of the constant must be the value. Use an = to delimit the key and value. The value must not contain quote characters.
    CATEGORY = Category
    DATA_FILES = Data Files
    ERROR = Error
    ERROR_OPENING_FILE = Error Opening File
    EXIT = Exit
    FILE = File
    GEOCODE = Geocode
    INVALID_FILE_TYPE = Invalid File Type
    NAME = Name
    NO_MATCHES = No Matches
    NUMBER = Number
    OPEN = Open
    PREFIX = Prefix
    READ = Read
    SUFFIX = Suffix
    USE_ALL_FIELDS = Use All Fields
    USE_NAME_ONLY = Use Name Only
    UTILITIES = Utilities
    WRITE = Write	  
    
    Expand
  2. Remove the declarations/initializations of the String constants from both WherezController and WherezWindow.
  3. Add a static ResourceBundle final attribute named STRINGS (with package visibility) to the WherezController class.
      static final ResourceBundle STRINGS;
    
    Expand
  4. Add code that reads in the ResourceBundle into the attribute named STRINGS when the class is loaded.
      static final ResourceBundle STRINGS = ResourceBundle.getBundle("wherez.gui.Strings");
    
    Expand
  5. Replace each String constant in WherezController with an appropriate call to STRINGS.getStrings().
        segFilter = new FileNameExtensionFilter(STRINGS.getString("DATA_FILES"), "seg");
        snkFilter = new FileNameExtensionFilter(STRINGS.getString("DATA_FILES"), "snk");
    
        // ...
    
        if      (ac.equals(STRINGS.getString("EXIT")))           System.exit(0);
        else if (ac.equals(STRINGS.getString("GEOCODE")))        geocode();
        else if (ac.equals(STRINGS.getString("OPEN")))           load(snkFilter, STRINGS.getString("OPEN"));
        else if (ac.equals(STRINGS.getString("READ")))           load(segFilter, STRINGS.getString("READ"));
        else if (ac.equals(STRINGS.getString("WRITE")))          write();
    
        // ...
    
        results.add(STRINGS.getString("NO_MATCHES"));
    
        results.add(STRINGS.getString("NO_MATCHES"));
    
        // ...
    
        JOptionPane.showMessageDialog(null, STRINGS.getString("ERROR_OPENING_FILE"), STRINGS.getString("ERROR"), JOptionPane.ERROR_MESSAGE);
    
        JOptionPane.showMessageDialog(null, STRINGS.getString("INVALID_FILE_TYPE"), STRINGS.getString("ERROR"), JOptionPane.ERROR_MESSAGE);
    
        // ...
    
        fileChooser.setDialogTitle(STRINGS.getString("WRITE"));
    
        JOptionPane.showMessageDialog(null, STRINGS.getString("ERROR_OPENING_FILE"), STRINGS.getString("ERROR"), JOptionPane.ERROR_MESSAGE);
    
        JOptionPane.showMessageDialog(null, STRINGS.getString("INVALID_FILE_TYPE"), STRINGS.getString("ERROR"), JOptionPane.ERROR_MESSAGE);
    
    
    Expand
  6. Replace each String constant in WherezWindow with an appropriate call to STRINGS.getStrings(). (Hint: You may want to add an import static statement to WherezWindow.)
    import static wherez.gui.WherezController.*;
    
    // ...
    
    geocodeButton = createJButton("Geocode.png", STRINGS.getString("GEOCODE"));
    openButton    = createJButton("Open.png",    STRINGS.getString("OPEN"));
    
    // ...
    
        menu = new JMenu(STRINGS.getString("FILE"));
        {
          item = new JMenuItem(STRINGS.getString("OPEN"));
          item.addActionListener(controller);
          menu.add(item);
    
          item = new JMenuItem(STRINGS.getString("EXIT"));
          item.addActionListener(controller);
          menu.add(item);
        }
        menuBar.add(menu);
    
        menu = new JMenu(STRINGS.getString("UTILITIES"));
        {
          item = new JMenuItem(STRINGS.getString("READ"));
          item.addActionListener(controller);
          menu.add(item);
          
          item = new JMenuItem(STRINGS.getString("WRITE"));
          writeItem = item;
          writeItem.setEnabled(false);
          item.addActionListener(controller);
          menu.add(item);
        }
        menuBar.add(menu);
    
    // ...
    
        entryPanel.add(createTitledComponent(STRINGS.getString("NUMBER"), numberField),     1,   0.0);
        entryPanel.add(createTitledComponent(STRINGS.getString("PREFIX"), prefixField),     1,   0.0);
        entryPanel.add(createTitledComponent(STRINGS.getString("NAME"), nameField),         3, 100.0);
        entryPanel.add(createTitledComponent(STRINGS.getString("CATEGORY"), categoryField), 1,   0.0);
        entryPanel.add(createTitledComponent(STRINGS.getString("SUFFIX"), suffixField),     1,   0.0);
    
    Expand
  7. Conduct some system tests to make sure you haven't introduced any defects.
  8. Add a static Locale attribute (with package visibility) named LOCALE to the WherezController class and initialize it when it is loaded using the static getDefault() method in the Locale class.
      static final Locale         LOCALE  = Locale.getDefault();
    
    Expand
  9. Modify each call to String.format() so that the first parameter is now LOCALE.
    
                                     
    Expand
  10. Conduct some system tests to make sure you haven't introduced any defects.
  11. Did you miss any String literals?
    Yes. Unfortunately we didn't use String constants everywhere.
    Expand
  12. What are the implications of your answer to the previous question?
    If there's any chance that a program will need to be localized/internationalized then there shouldn't be String literals interspersed throughout the code.
    Expand
  13. Create a file for another language. (If you speak another language, feel free to do the translation yourself. If not, a good approach is to use Google Translate.)
  14. Conduct system tests using the second language. Ensure that all of the acceptance criteria are satisfied.

Copyright 2021