Creating a Resource Bundle

To create a default resource bundle:

  1. Create a new Java class called MyResources, that extends class java.util.ListResourceBundle.
  2. Modify the getContents method in the following way:
      public Object[][] getContents() {
        return contents;
      }
    
  3. Declare an object array like the following:
      static final Object[][] contents = {
      };
    }
    
  4. Add an entry for each item of text you need on your pages, giving a key and the text for that key. For example, in the following example, the comments indicate the strings that must be translated into other languages:
      static final Object[][] contents = {
        // LOCALIZE THIS
        {"CompanyName", "AnyCo Corporation"},
        {"SiteName", "HR Application"},
        {"FilterButton", "Filter"},
        {"UpdateButton", "Update"},
        // END OF MATERIAL TO LOCALIZE
      };
    

    The complete resource bundle class should look similar to that shown in the following code example.

    Creating a Resource Bundle Class

    public class MyResources extends ListResourceBundle {
        public MyResources() {
            super();
        }
     
      protected Object[][] getContents() {
         return contents;
       }
       static final Object[][] contents = {
         // LOCALIZE THIS
         {"CompanyName", "AnyCo Corporation"},
         {"SiteName", "HR Application"},
         {"FilterButton", "Filter"},
         {"UpdateButton", "Update this Record"},
         // END OF MATERIAL TO LOCALIZE
       };
    }
    

    To globalize your application, you must create the locale-specific versions of the resource bundle for the different locales you are supporting, containing text for the items in each language.