zoukankan      html  css  js  c++  java
  • Java学习之国际化程序

    国际化程序就是把程序的语言根据用户使用的语言显示,各个国家的用户都可以看懂

    实现方法就是把输出文字都写在配置文件里,然后根据用户系统语言选择不同的语言输出

     1 package com.gh;
     2 
     3 import java.text.MessageFormat;
     4 import java.util.Locale;
     5 import java.util.ResourceBundle;
     6 import java.util.Scanner;
     7 /**
     8  * 国际化程序
     9  * 用配置文件改变输出语言
    10  * @author ganhang
    11  *
    12  */
    13 public class dome {
    14     public static void main(String[] args) {
    15         //实例化locale
    16         Locale locale = Locale.getDefault();
    17         //配置文件和locale绑定
    18         ResourceBundle res = ResourceBundle.getBundle("com.gh.info", locale);
    19         Scanner sc = new Scanner(System.in);
    20         String usenamekey = res.getString("usename");
    21         String passwordkey = res.getString("password");
    22         String inputkey = res.getString("input");
    23         String infosuccess = res.getString("info.success");
    24         String infoerro = res.getString("info.erro");
    25         System.out.println(inputkey + usenamekey);
    26         String username = sc.next();
    27         System.out.println(inputkey + passwordkey);
    28         String pwd = sc.next();
    29         if ("admin".equals(username) && "123".equals(pwd)) {
    30             String info =MessageFormat.format(infosuccess,username);
    31             System.out.println(info);
    32         }
    33         else 
    34             System.out.println(infoerro);
    35     }
    36 }

    配置文件

    info_zh_CN.properties

    usename=u7528u6237u540D
    password=u5BC6u7801
    input=u8BF7u8F93u5165
    info.success=u767Bu5F55u6210u529FuFF0C{0}
    info.erro=u7528u6237u540Du6216u5BC6u7801u9519u8BEF
  • 相关阅读:
    Google MapReduce/GFS/BigTable三大技术的论文中译版
    Statistic flags are not updated in SRM PO
    漫谈PPS 1: Cancel PO, Reverse PO
    Team Purchasing
    对于SRM与ECC的IDocs处理逻辑及解决
    Bugs&Standard Behavior汇总 (持续更新ING…)
    Sourcing Cockpit: 2. Demo of Service Purchase Order
    POWL List Refresh
    漫谈PPS 2: Acceptance at Origin
    Redesign and bugs fix of SRM Classic Transfer
  • 原文地址:https://www.cnblogs.com/ganhang-acm/p/5154128.html
Copyright © 2011-2022 走看看