js国际化解决方案(使用 jQuery.i18n.properties)

//设置语言
httpServletRequest.getSession().setAttribute("currUser_language",langType!=null?langType:"zh_CN");


<#assign currUser_language = Session["currUser_language"]>
<#assign path="${request.contextPath}">
<script language="JavaScript">
    var ctx = '${path}';
    var currUser_language = '${currUser_language}';
</script>


<script type="text/javascript" src="${path}/statics/common/js/easy-ui/easyui/1.3.4/locale/easyui-lang-${currUser_language}.js"></script>

<script type="text/javascript" src="${path}/statics/common/js/i18n/jquery.i18n.properties-1.0.9.js"></script>


<script>
    var language_pack = {
        now_lang : "zh_CN",
        loadProperties : function(new_lang){
            var self = this;
            var tmp_lang = new_lang;
            jQuery.i18n.properties({//加载资浏览器语言对应的资源文件
                name: 'strings', //资源文件名称
                path:ctx + '/statics/common/js/i18n/language/', //资源文件路径
                language: tmp_lang,
                cache: false,
                mode:'map', //用Map的方式使用资源文件中的值
                callback: function() {//加载成功后设置显示内容
                    /*for(var i in $.i18n.map){
                        $('[data-lang="'+i+'"]').text($.i18n.map[i]);
                    }
                    document.title = $.i18n.map['string_title'];*/
                    //alert($.i18n.map['string_title']);
                    //alert($.i18n.prop('string_hello',new_lang,new_lang));
                }
            });
            self.now_lang = new_lang;
        }
    };
    $(document).ready(function(){
        language_pack.loadProperties(currUser_language);
    });
</script>


strings_en.properties:

common.edit=Edit
common.add=Add
common.delete=Delete
strings_zh_CN.properties:

common.edit=编辑
common.add=添加
common.delete=删除

js中使用如下:

$.i18n.map['common.save']
$.i18n.prop('string_hello','110','cde')  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值