`

jquery.i18n.properties使用小记

 
阅读更多
http://blog.sina.com.cn/s/blog_5919afb30100fw84.html

项目主页: https://code.google.com/p/jquery-i18n-properties/

一直在寻找js的i18n解决方案,今天使用了一下jquery.i18n.properties觉得很不错,向大家推荐一下。

在jquery.1.3.2下调试过程

1、在js/i18n/目录下创建message.properties,message_zh_CN.properties,message_en_US.properties三个文件,推荐使用eclipse下的插件resourcebundleeditor编辑文档,文档存为ISO-8859-1或utf-8.
英文文件中插入
   msg_hello = Hello
    msg_world = World
    msg_complex = Good morning {0}!

中文同上就不写了。
2、在使用前初始化jquery.i18n.properties。
 
// This will initialize the plugin
// and show two dialog boxes: one with the text "Olá World"
// and other with the text "Good morning John!"
jQuery.i18n.properties({
    name:'message', //使用资源文件名称
    path:'js/i18n/', //资源文件所在路径
    mode:'both',    //调用方式,可用值‘vars’ (default) 变量方式, ‘map’map方式 or ‘both’两者均支持
    language:'en_US', //语言
    callback: function() {
        //回调函数
        // We specified mode: 'both' so translated values will be
        // available as JS vars/functions and as a map

        // Accessing a simple value through the map 通过map调用
        jQuery.i18n.prop('msg_hello');
        // Accessing a value with placeholders through the map 带参数Map调用,john会替换相应参数,支持多个参数
        jQuery.i18n.prop('msg_complex', ['John']);

        // Accessing a simple value through a JS variable通过变量调用
        alert(msg_hello +' '+ msg_world);
        // Accessing a value with placeholders through a JS function通过变量函数方式替换占位符,支持多个参数,不过在360浏览器下测试失败,在chrome下成功
        alert(msg_complex('John'));
    }
});

使用心得:
建议使用工具编辑i18n文件,方便。
为了获得最好的兼容性,还是使用map方式访问吧
分享到:
评论

相关推荐

    基于jQuery.i18n.properties插件实现前端页面国际化demo

    jQuery.i18n.properties插件是实现这一目标的一个强大工具,尤其适合那些基于jQuery构建的项目。这个插件提供了一种简单的方法来管理并加载不同语言版本的属性文件,使得前端开发者可以轻松地实现在不同地区使用的多...

    jquery.i18n.properties.zip

    使用jQuery.i18n.properties的步骤如下: 1. **下载与引用**:首先,你需要从可靠的源获取jquery.i18n.properties.js文件,将其放入项目的JavaScript文件夹下。确保在HTML或JSP页面中正确引入jQuery库和这个插件,...

    jquery.i18n.properties在asp.net里的应用

    - **JavaScript 调用**:在页面的 JavaScript 部分,使用 jQuery.i18n.properties 的方法来获取和显示资源。例如: ```javascript $.i18n.properties({ name: 'Messages', // properties file name path: 'App...

    jquery.i18n.properties-1.2.2.js (最新)

    jQuery.i18n.properties()、jQuery.i18n.prop()、jQuery.i18n.browserLang(),当然也可以采用.i18n.properties()、.i18n.properties()、.i18n.prop()、$.i18n.browserLang()的形式使用这些API。

    jquery.i18n.properties两个js文件打包

    `jquery.i18n.properties`是一个非常实用的jQuery插件,它专门用于在前端动态读取和使用`.properties`文件的内容,以实现国际化(i18n)功能。这篇文章将详细介绍这个插件的工作原理、使用方法及其相关知识点。 ...

    在javascript文件中读取properties文件需要的插件jquery.i18n.properties-min-1.0.9.js

    在提供的压缩包中,`jquery.i18n.properties-1.0.9.js`是插件的源文件,而`使用方法地址.txt`可能包含了更多关于如何使用这个插件的详细说明。阅读这个文本文件可以帮助你更好地理解和应用这个插件。总之,`jquery....

    jquery.i18n.properties.js.rar

    jquery.i18n.properties-min-1.0.9.js前端国际化文件,项目中用到的前端国际化文件。 $.i18n.properties( { name : 'web_i18n', // Resource name path : '/resources/i18n/', //Resource path cache : true, mode :...

     jquery.i18n.properties.js

    jquery.i18n.properties是一款轻量级的国际化插件,采用.properties文件来对javascript文件进行国际化,即...jquery.i18n.properties的使用讲解与实例: https://blog.csdn.net/m0_37566424/article/details/79070218/

    jquery.i18n.properties-1.0.9.js

    jquery.i18n.properties-1.0.9.js 下载

    jquery.i18n.properties-min-1.0.9.js

    jquery.i18n.properties-min-1.0.9 主要用于国际化和读取properties文件

    jquery.i18n.properties和jquery.easyui.min

    jQuery.i18n.properties({ name : "common", //资源文件名称 path : $.contextPath+"/i18n/"+i18nLanguage+"/", //资源文件路径 mode : 'map', //用Map的方式使用资源文件中的值 language : i18nLanguage, ...

    jquery.i18n.properties国际化 例子

    本文将详细讲解jQuery.i18n.properties插件的使用方法,以及如何结合实际项目中的示例进行国际化设置。 首先,我们需要理解什么是.properties文件。这是一种Java平台上的资源配置文件,用于存储软件应用中的字符串...

    jquery.i18n.properties.min.js

    jquery.i18n.properties.min.js

    基于jQuery.i18n.properties 实现资源国际化简单Demo 源码

    本文将深入探讨如何使用jQuery.i18n.properties库实现前端页面的资源国际化,并通过一个简单的Demo源码进行说明。 首先,我们要了解什么是jQuery.i18n.properties。这是一个jQuery插件,专门用于处理Web应用中的...

    jquery.i18n.properties-min-1.0.9.js文件下载

    3. **初始化插件**:在JavaScript中,通过调用jQuery的`.i18n()`方法进行初始化,指定.properties文件的位置。 4. **使用本地化文本**:在需要显示本地化文本的地方,使用`.i18n.prop()`方法,传入对应的键名,插件...

    jQuery.i18n.properties

    **jQuery.i18n.properties** 是一个用于前端页面国际化的jQuery插件,它使得Web应用能够根据用户所在的地区和语言,动态地展示相应的文本内容。这个插件是基于`jQuery`库设计的,目的是简化多语言环境下的网页开发,...

    jquery.i18n.properties-min-1.0.9

    只需重新调用`.i18n.properties`并传入新的语言标识,即可实时更新页面上的文本。 7. **优化与性能** 考虑到前端性能,可以将`.properties`文件转换成JSON格式,或者利用服务端缓存和CDN加速文件的加载。此外,...

    jquery.i18n.properties-min 全套

     jQuery.i18n.properties({  name:'Messages',   path:'bundle/',   mode:'both',  language:lang,   callback: function() {  updateExamples();  }  });  } function loadProperties(){  jQuery....

Global site tag (gtag.js) - Google Analytics