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.properties
		ResourceBundle resource = ResourceBundle.getBundle("info", locale);
//		ResourceBundle resource = ResourceBundle.getBundle("info", Locale.CHINESE);
//		ResourceBundle resource = ResourceBundle.getBundle("info", Locale.SIMPLIFIED_CHINESE);

		// info_en_US.properties
		String 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_第1张图片

i18n internationalization_第2张图片

你可能感兴趣的:(java,java,i18n)