<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.
    主站蜘蛛池模板: 日日躁狠狠躁狠狠爱免费视频| 亚洲色图视频在线观看| 亚洲av片在线观看| 久久九九兔免费精品6| 一区二区三区亚洲| 免费A级毛片无码A∨中文字幕下载| AV无码免费永久在线观看| 亚洲高清资源在线观看| 精品国产sm捆绑最大网免费站| 在线观看成人免费视频| 亚洲狠狠婷婷综合久久蜜芽| 日本v片免费一区二区三区| 久久精品国产亚洲AV未满十八| 三年片在线观看免费西瓜视频| 精品久久8x国产免费观看| 亚洲一级毛片在线观| 日韩亚洲国产高清免费视频| 亚洲AV日韩综合一区尤物| 免费无码又爽又刺激高潮| 美女被羞羞网站免费下载| www.亚洲精品.com| a毛片久久免费观看| 亚洲色偷偷av男人的天堂| 亚洲一区二区久久| 黄网址在线永久免费观看 | 亚洲成人激情在线| 69pao强力打造免费高清| 亚洲精品第一综合99久久| 永久免费av无码网站大全| 一区二区三区免费看| 久久亚洲一区二区| 大地资源二在线观看免费高清| 亚洲爆乳精品无码一区二区三区 | 亚洲国产av玩弄放荡人妇| 国产成人无码免费视频97| 国产午夜无码片免费| 亚洲成人福利在线观看| 亚洲国产精品成人一区| 人人玩人人添人人澡免费| 亚洲日韩国产AV无码无码精品| 美女被免费喷白浆视频|