Saturday, March 23, 2019

ResourceBundle Example

import java.util.Locale;
import java.util.ResourceBundle;
public class Application {
public static void main(String[] args) {
System.out.println("Current Locale: " + Locale.getDefault());
ResourceBundle mybundle = ResourceBundle.getBundle("Labels");
System.out.println("Say you are the best in US English: " + mybundle.getString("you-are-the-best"));
Locale.setDefault(new Locale("zh", "CN"));
System.out.println("Current Locale: " + Locale.getDefault());
mybundle = ResourceBundle.getBundle("Labels");
System.out.println("Say you are the best in Chinese: " + mybundle.getString("you-are-the-best"));
}
}

Labels_en_US.properties 

you-are-the-best = you are Not Only the Best But the Greatest of All Time

Labels_zh_CN.properties 

you-are-the-best = I Don't Know Chinese




No comments:

Post a Comment