5.4. Build a resource bundle for each locale - Source Code

MyApp.properties:

okButtonLabel=Default.Ok
cancelButtonLabel=Default.Cancel
					

MyApp_be_BY.properties:

okButtonLabel=Добра
cancelButtonLabel=Скасаваць
					

MyApp_en_US.properties:

okButtonLabel=Ok
cancelButtonLabel=Cancel
					

Code:

package c5.s4;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @author Mikalai Zaikin
 */
public class PropertiesResourceBundleDemo {
    public static void main(String... args) {

      ResourceBundle enLabels = ResourceBundle.getBundle("c5.s4.MyApp");
      System.out.println("'Ok' button: " + enLabels.getString("okButtonLabel"));
      System.out.println("'Cancel' button: " + enLabels.getString("cancelButtonLabel"));
      System.out.println();

      ResourceBundle beLabels = ResourceBundle.getBundle("c5.s4.MyApp", new Locale("be", "BY"));
      System.out.println("'Ok' button: " + beLabels.getString("okButtonLabel"));
      System.out.println("'Cancel' button: " + beLabels.getString("cancelButtonLabel"));
   }
}
					

output:

'Ok' button: Ok
'Cancel' button: Cancel

'Ok' button: Добра
'Cancel' button: Скасаваць
					

Professional hosting         Free 'Oracle Certified Expert Web Services Developer 6' Guide     Free SCDJWS 5.0 Guide