zoukankan      html  css  js  c++  java
  • 每日日报8月29日

    1.今天学习

    实现用户管理界面的国际化

    html页面的国际化(含Javascript的国际化)采用读取Properties文件的方式。和文中不一样的是,不再是用户手动选择语言版本,而是改用js读取语言版本配置文件来决定读取哪个版本资源文件。代码大致如下:

    1.  
      var bLoad= false;
    2.  
      function getRootPath() {
    3.  
      var pathName = window.location.pathname.substring(1);
    4.  
      var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
    5.  
      return window.location.protocol + '//' + window.location.host + '/'+ webName;
    6.  
      }
    7.  
       
    8.  
      function GetValueByKey(key){
    9.  
      if(!bLoad)
    10.  
      {
    11.  
      loadProperties();
    12.  
      bLoad=true;
    13.  
      }
    14.  
      var value = $.i18n.prop(key);
    15.  
      return value;
    16.  
      };
    17.  
       
    18.  
      function loadProperties(){
    19.  
      var JsSrc = (navigator.language || navigator.browserLanguage).toLowerCase();
    20.  
      if(JsSrc.indexOf('zh')>=0)
    21.  
      {
    22.  
      JsSrc = 'js_zh_CN';
    23.  
      }
    24.  
      else if(JsSrc.indexOf('en')>=0)
    25.  
      {
    26.  
      JsSrc = 'js_en_US';
    27.  
      }
    28.  
      else
    29.  
      {
    30.  
      JsSrc = 'js_zh_CN';
    31.  
      }
    32.  
       
    33.  
      var i18npath = getRootPath()+ "/resources/js/"
    34.  
      jQuery.i18n.properties({//加载资浏览器语言对应的资源文件
    35.  
      name:JsSrc, //资源文件名称
    36.  
      path: i18npath, //'resources/js/', //资源文件路径
    37.  
      mode:'map', //用Map的方式使用资源文件中的值
    38.  
      callback: function() {//加载成功后设置显示内容
    39.  
       
    40.  
      }
    41.  
      });
    42.  
      };

           其它的js可以这样调用:
    1.  
      document.write("<script language=javascript src='common/taglibs.js'></script>"); // 这句放在最前面
    2.  
      var key = “user”;
    3.  
      var value = GetValueByKey(key);

           

          java部分的国际化,采用读取语言配置文件,语言配置文件大致如下:

    1.  
      <?xml version="1.0" encoding="UTF-8" ?>
    2.  
      <properties>
    3.  
      <category name="LangConf">
    4.  
      <property name="Lang" value="en_US" /> <!-- zh_CN --> <!-- en_US -->
    5.  
      </category>
    6.  
      </properties>

    然后增加一个Java读取这个配置文件的类:

    1.  
      // 读取语言配置文件的语言配置类
    2.  
      public class LangConfInit {
    3.  
      public static String language = null;
    4.  
      public static ResourceBundle rb=null;
    5.  
      public LangConfInit(){
    6.  
      if(null == language && null == rb){
    7.  
      language = ConfigUtil.getProperty("LangConf","Lang");
    8.  
      rb = ResourceBundle.getBundle("message_"+language);
    9.  
      }
    10.  
      }
    11.  
       
    12.  
      public String GetValue(String key)
    13.  
      {
    14.  
      try {
    15.  
      String keyValue = new String(rb.getString(key).getBytes("ISO-8859-1"), "utf-8");
    16.  
      return keyValue;
    17.  
      } catch (UnsupportedEncodingException e) {
    18.  
      e.printStackTrace();
    19.  
      }
    20.  
      return null;
    21.  
      }

    调用代码如下:

    1.  
      public LangConfInit lang =new LangConfInit();
    2.  
      String vaule = lang.GetValue("user");
    2.没有遇到问题
    3.明天打算学习
    数字的格式化
  • 相关阅读:
    轮播 margin-left实现
    点击按钮切换图片
    运用把不同的方式排版,涉及到float box-flox box-orient
    chrome中font-size<12px时并不更改字体大小仍未12px
    js实现跑马灯
    支付宝支付集成
    前端技术博客
    在iphone5/5s出现界面显示不全,大小为iphone4/4s 的问题
    UIImage使用总结
    在IOS开发中使用自定义的字体
  • 原文地址:https://www.cnblogs.com/wanghaoning/p/13591981.html
Copyright © 2011-2022 走看看