美文网首页
web国际化jQuery.i18n.properties

web国际化jQuery.i18n.properties

作者: YQSummer | 来源:发表于2020-12-26 17:13 被阅读0次

    第一步:引入资源文件

    //jquery版本
        <script src="./js/jquery-1.7.2.min.js"></script> 
    //query-i18n-properties
        <script src="https://cdn.jsdelivr.net/gh/jquery-i18n-properties/jquery-i18n-properties/jquery.i18n.properties.min.js"></script> |//
        
    <script src="./js/lang.js"></script>
    
    

    lang.js

    function  loadProperties(){
        var i18nLanguage = 'en'; //当前语言
        $.i18n.properties({
            name:'string',//翻译文件的前缀
            path:'language/',
            //资源文件路径
            mode:'map',
            // 用Map的方式使用资源文件中的值
            language:i18nLanguage,
            callback:function(){
                $("[data-lang]").each(function(){
                    $(this).html($.i18n.prop($(this).data("lang")));
                });
            }
        });
    }
    
    
    //页面调用翻译
    $(function(){
      loadProperties();
    })
     
    
    
    //html样式
       <strong data-lang="title">标题</strong>
      <div data-lang="content"><div>
    
    

    不同语言翻译文件.properties
    文件内容

    title = 测试标题
    content =测试内容
    
    image.png

    相关文章

      网友评论

          本文标题:web国际化jQuery.i18n.properties

          本文链接:https://www.haomeiwen.com/subject/iyugnktx.html