软件的国际化

    软件开发时,要使它能同时应对世界不同地区和国家的访问,并针对不同地区和国家的访问,提供相应的、符合来访者阅读习惯的页面或数据。


国际化又称为 i18n:internationalization


软件实现国际化,需具备哪些特征:

    对于程序(页面)中固定使用的文本元素,例如菜单栏、导航条等中使用的文本元素、或错误提示信息,状态信息等,需要根据来访者的地区和国家,选择不同语言的文本为之服务。

    对于程序动态产生的数据,例如(日期,货币等),软件应能根据当前所在的国家或地区的文化习惯进行显示。

页面固定文本的国际化_fmt标签实现页面国际化

ascii码没有中文,可以将中文进行unicode编码表示形式保存

 

 

2.国际化的组成部分:

    (1)页面中固定文本元素的国际化

  ResourceBundle 代表资源包的对象

       ResourceBundlesrc目录下寻找基名为resource的文件

   ResourceBundle在查找资源文件时,首先找指定的,如果找不到,找操作系统语言环境    

 ,如果还找不到,用默认的

        ResourceBundle bundle = ResourceBundle.getBundle("resource",Locale.FRANCE);

        String value = bundle.getString("username");

        System.out.println(value);

 

web应用如何实现国际化

  <%

  Locale local = request.getLocale();

  ResourceBundle bundle = ResourceBundle.getBundle("resource",local);

   %>

  <form action="#">

  <%=bundle.getString("username") %>:<input type="text"/>

  <%=bundle.getString("password") %>:<input type="password"/>

  <input type="submit" value="<%=bundle.getString("submit") %>"/>

  </form>

 

国际化标签<fmt>

   <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

   <fmt:setBundle basename="resource" var="bundle" scope="page"/>

  <form action="#">

  <fmt:message bundle="${bundle}" key="username"/>:<input type="text"/>

  <fmt:message bundle="${bundle}" key="password"/>:<input type="password"/>

  <input type="submit" value="<fmt:message bundle="${bundle}" key="submit"/>"/>

  </form>


(2)对程序动态产生的数据的国际化 -- 日期时间/货币

 

~1.日期时间DateFormat -- SimpleDateFormat

static DateFormat getDateInstance()

        获取日期格式器,该格式器具有默认语言环境的默认格式化风格。

static DateFormat getDateInstance(int style)

        获取日期格式器,该格式器具有默认语言环境的给定格式化风格。

static DateFormat getDateInstance(int style, Locale aLocale)

        获取日期格式器,该格式器具有给定语言环境的给定格式化风格。

 

 

static DateFormat getTimeInstance()

        获取时间格式器,该格式器具有默认语言环境的默认格式化风格。

static DateFormat getTimeInstance(int style)

        获取时间格式器,该格式器具有默认语言环境的给定格式化风格。

static DateFormat getTimeInstance(int style, Locale aLocale)

        获取时间格式器,该格式器具有给定语言环境的给定格式化风格。

 

 

static DateFormat getDateTimeInstance()

        获取日期/时间格式器,该格式器具有默认语言环境的默认格式化风格。

static DateFormat getDateTimeInstance(int dateStyle, int timeStyle)

        获取日期/时间格式器,该格式器具有默认语言环境的给定日期和时间格式化风格。

static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)

        获取日期/时间格式器,该格式器具有给定语言环境的给定格式化风格。

 

String format(Date date)

 

 

 

 

~2.货币

static NumberFormat getCurrencyInstance()

        返回当前默认语言环境的货币格式。

static NumberFormat getCurrencyInstance(Locale inLocale)

        返回指定语言环境的货币格式。

 

1000 -- >   $1000.00 1000.00

~3.消息国际化