<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.
    主站蜘蛛池模板: 国产精品免费看久久久香蕉| 国产亚洲精品免费| 最近2019中文字幕免费看最新| 99热在线精品免费全部my| 成人免费看黄20分钟| 全黄a免费一级毛片人人爱| 亚洲熟妇无码AV在线播放| 日韩免费视频一区| 99久久这里只精品国产免费 | 亚洲精品久久无码av片俺去也| 亚洲AV日韩AV高潮无码专区| 超清首页国产亚洲丝袜| 国产美女a做受大片免费| 亚洲精品无码久久久| 又粗又硬又黄又爽的免费视频| 国产亚洲情侣一区二区无码AV| 亚洲伊人tv综合网色| 亚洲精品伦理熟女国产一区二区| 九九综合VA免费看| 最近中文字幕高清免费中文字幕mv| 精品国产免费人成网站| 一级做受视频免费是看美女| 暖暖免费在线中文日本| 免费在线观看一级片| 国语成本人片免费av无码| 色窝窝免费一区二区三区| 一本色道久久88亚洲综合| 亚洲AV永久无码精品| 久久久亚洲裙底偷窥综合| 亚洲成a∧人片在线观看无码| 好猛好深好爽好硬免费视频| 67194熟妇在线永久免费观看| 国产va免费精品观看精品| 亚洲国产成人精品91久久久| 亚洲视频在线观看地址| 国产成人亚洲精品播放器下载| 黄页网址在线免费观看| 中文字幕免费视频| 亚洲裸男gv网站| 亚洲伊人久久大香线蕉结合| 久草免费福利在线|