本文主要是介绍i18n internationalization,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
package i18n;import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;/*** 国际化internationalization* i18n** @author ZengWenFeng* @date 2015.11.23*/
public class I18nDemo
{public static void main(String[] args){Locale locale = new Locale("zh", "CN");
// Locale locale = new Locale("en", "US");Locale l01 = Locale.US;Locale l02 = Locale.getDefault();System.out.println("C = " + l01.getCountry());System.out.println("L = " + l01.getLanguage());System.out.println("C = " + l02.getCountry());System.out.println("L = " + l02.getLanguage());//// E:\PRJ_J2EE\PrjFlexJava\java_src\info_en_US.propertiesResourceBundle resource = ResourceBundle.getBundle("info", locale);
// ResourceBundle resource = ResourceBundle.getBundle("info", Locale.CHINESE);
// ResourceBundle resource = ResourceBundle.getBundle("info", Locale.SIMPLIFIED_CHINESE);// info_en_US.propertiesString username = resource.getString("username");String password = resource.getString("passwd");String infoSuccess = resource.getString("info.success");String infoError = resource.getString("info.error");String v_userName = "admin";String v_password = "123";if (v_userName.equals(username) && v_password.equals(password)){String success = MessageFormat.format(infoSuccess, username);System.out.println(success);}else{System.out.println(infoError);}}
}
这篇关于i18n internationalization的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!