<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小明思考

    Just a software engineer
    posts - 124, comments - 36, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    java i18n kit

    Posted on 2005-12-19 17:26 小明 閱讀(1137) 評論(1)  編輯  收藏 所屬分類: 開發日志

    Here is my some recommendations for java i18n .

    1.  The correct way to handle text-based resource files for localization

     Use java.util.ResourceBoundle to read resource from file.

    e.g.
     Local local = Local.CHINA;
     ResourceBundle rb = ResourceBundle.getBundle("test", local);
     String title = rb.getString("helloworld.title");
     System.out.println(title);

     //The program will read file: test_zh.properties
     # This locale is zh_CN
     # helloworld.title=中文1234
     and the file should use native2ascii program to convert (native2ascii.exe is in JDK)
     # This locale is zh_CN
     helloworld.title=\u4f60\u597d1234

     if you don't use native2ascii  to covert,you must covert it in the java program,like this:
     ResourceBundle rb = ResourceBundle.getBundle("test", Locale.CHINA);
         String title = rb.getString("helloworld.title");
        System.out.println(new String(title.getBytes("8859_1")));  //covert to os/jvm default charset

    2.       Locale driven date and time display
     
     Use java.text.DateFormat to format date string
    e.g.
     DateFormat df = DateFormat.getDateInstance(DateFormat.FULL,Locale.CHINA);
     String date = df.format(new Date());
        System.out.println(date);

     DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.DEFAULT,Locale.CHINA);
     String datetime = df2.format(new Date());
        System.out.println(datetime);

    3.       JSP localization method.

    1) native method:
     use "Local local = request.getLocale();" to get the page accessor's local info
     then use ResourceBoundle to read local resource
     and page should use utf-8 charset
     
    e.g.
    <%@ page contentType="text/html; charset=utf-8" %>
    <%
    Local local = request.getLocale();
    ResourceBundle rb = ResourceBundle.getBundle("test", local);
    String title = rb.getString("helloworld.title");
    %>
    <html>
    <head>
    <title>test</title>
    </head>
    <body bgcolor="#ffffff">
    <h1><%=title%></h1>
    </body>
    </html>
    notice:put the  test_zh.properties into directionary WEB_INF/classes

    2)use jsp taglib to simplify the page

     the Jakarta i18n taglib is a good choice. http://jakarta.apache.org/taglibs/doc/i18n-doc/index.html
    e.g.
    <%@ page contentType="text/html; charset=utf-8"%>
    <%@ taglib uri="<i18n:bundle baseName="test" id="test" localeRef="userLocale"
                 scope="request"
                 changeResponseLocale="false"/>
    <html>
    <head>
    <title>test</title>
    </head>
    <body bgcolor="#ffffff">
    <h1><i18n:message key="helloworld.title" /></h1>
    </body>
    </html>

    3)use j2ee web framework(Struts) to simplify

     the Struts web framework supply i18n support
     Please refer:
    http://www.allapplabs.com/struts/struts_internationalization.htm


    評論

    # re: java i18n kit  回復  更多評論   

    2005-12-19 23:03 by no name(anonimous)
    Hi,budy.
    Your recommendation is very convenion for I have been disturbing by these damned localization problems at every forum about java technology.
    主站蜘蛛池模板: 免费观看无遮挡www的视频| 四虎免费在线观看| 99国产精品视频免费观看| 久久夜色精品国产亚洲av| 一级毛片**免费看试看20分钟| 免费久久精品国产片香蕉| 亚洲精品无码久久一线| 国产免费高清69式视频在线观看 | 一级毛片人与动免费观看| 永久免费毛片手机版在线看| 美腿丝袜亚洲综合| 香蕉视频在线免费看| 亚洲精品国产精品乱码视色| 日韩视频免费在线观看| 亚洲成人一区二区| jizz免费观看视频| 国产精品亚洲аv无码播放| 无人在线观看免费高清| 亚洲精品午夜久久久伊人| 无码国产精品一区二区免费式直播| 亚洲综合无码精品一区二区三区| 狠狠色伊人亚洲综合网站色| 成人爱做日本视频免费| 亚洲成年人电影在线观看| 一级做a免费视频观看网站| 亚洲午夜久久久影院伊人| 91免费国产精品| 亚洲综合色7777情网站777| 国产成人精品免费直播| 亚洲丝袜中文字幕| 免费国产精品视频| 嫩草成人永久免费观看| 亚洲一区免费视频| 免费吃奶摸下激烈视频| 久久青草免费91线频观看站街| 亚洲av无码久久忘忧草| 丁香亚洲综合五月天婷婷| 久久精品亚洲日本波多野结衣| 亚洲综合无码精品一区二区三区 | 免费国产成人α片| 亚洲中文字幕无码一区二区三区 |