<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 小明 閱讀(1129) 評論(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.
    主站蜘蛛池模板: 三年片免费观看大全国语| 精品亚洲视频在线观看| 精品一区二区三区免费| 国产精品成人观看视频免费 | 亚洲精品V欧洲精品V日韩精品| 波多野结衣免费视频观看| 亚洲精品国产专区91在线| 亚洲人成在线中文字幕| 久久精品免费大片国产大片| 24小时免费直播在线观看| 欧洲精品免费一区二区三区| 免费一级毛片一级毛片aa| 亚洲午夜成激人情在线影院| 精品一区二区三区免费视频| 免费无码又爽又刺激毛片| 亚洲AV日韩精品久久久久| 免费一级特黄特色大片| 免费中文熟妇在线影片| 亚洲精品天天影视综合网| 国产免费牲交视频免费播放 | 国产伦精品一区二区三区免费下载 | 国产亚洲老熟女视频| 亚洲精品无码久久久久sm| 无码一区二区三区亚洲人妻| 欧洲精品码一区二区三区免费看| 偷自拍亚洲视频在线观看99| 免费视频专区一国产盗摄| 亚洲视频在线免费观看| 中国毛片免费观看| 91视频国产免费| 亚洲男人电影天堂| 久久大香香蕉国产免费网站 | 永久亚洲成a人片777777| 国产午夜亚洲精品不卡电影| 91成人免费福利网站在线| 亚洲av无码成人精品区在线播放 | 日韩吃奶摸下AA片免费观看| 91天堂素人精品系列全集亚洲| 亚洲精品9999久久久久无码| 免费无码精品黄AV电影| 亚洲一区二区三区在线播放|