jquery-i18n-properties国际化(最简单案例)
来源:互联网 发布:christopher bu知乎 编辑:程序博客网 时间:2024/06/06 02:10
概述:
最近需要需要整国际化,网上有很多例子,但是本人资质愚钝,看不懂。。。记录一下怎么实现最简单的国际化,(通了就好说,不通感觉怀疑人生了),关于国际化的概念就免了(不同国家看到不同语言),实战为主,GitHub最新国际化js不会用,报错。
1、准备
工具:Eclipse,Tomcat
下载对应js文件:
a、jquery.i18n.properties-1.0.9.js
b、Download the compressed, production jQuery 3.2.1 (也就是jquery)
2、文件放置位置
文件清单:
- 1、strings_zh.properties (表示中文属性文件)
- 2、strings.properties (表示默认情况下属性文件)
- 3、jquery.i18n.properties-min-1.0.9.js(国际化需要文件)
- 4、jquery.js (jquery.js文件,把版本号给删掉)
- 5、test.html (展示html页面)
文件结构:
3、文件内容
3.1、string_zh.properties (注意属性文件创建字符编码是ISO-8859-1格式,可以修改成UTF-8,否则汉字显示不出来)
右键string_zh.properties->Properties(最下面的选项)->Text file encoding
username=用户名:password=密码:
3.2、strings.properties
username=User Name:password=Password:
3.3、test.html
<html lang="en"><head> <meta charset="UTF-8"> <title>国际化</title></head><body> <label data-locale="username">用户名:</label><input type="text"> <label data-locale="password">密码:</label><input type="password"> <script src="../lib/jquery.js"></script> <!-- 加载语言包文件 --> <script src="../lib/jquery.i18n.properties-min-1.0.9.js"></script> <script type="text/javascript"> loadProperties(); function loadProperties() { $.i18n.properties({ name:'strings', //属性文件名 命名格式: 文件名_国家代号.properties path:'../i18n/', //注意这里路径是你属性文件的所在文件夹 mode:'map', language:"zh", //这就是国家代号 name+language刚好组成属性文件名:strings+zh -> strings_zh.properties callback:function(){ $("[data-locale]").each(function(){ console.log($(this).data("locale")); $(this).html($.i18n.prop($(this).data("locale"))); }); } }); } </script> </body></html>language的还可以根据浏览器来确定选择属性文件,把上面language:"zh"改为:language:$.i18n.browserLang()
4、将应用添加Tomcat启动
---------------------------谢谢你宝贵的时间
阅读全文
0 0
- jquery-i18n-properties国际化(最简单案例)
- jQuery之前端国际化jQuery.i18n.properties
- jQuery之前端国际化jQuery.i18n.properties
- jQuery之前端国际化jQuery.i18n.properties
- jQuery.i18n.properties实现js国际化
- jQuery.i18n.properties实现前端国际化
- Web前端国际化之jQuery.i18n.properties
- js国际化解决方案(使用 jQuery.i18n.properties)
- jQuery.i18n.properties实现前端国际化
- jquery i18n(前端国际化)
- 使用 jQuery.i18n.properties 实现 Web 前端的国际化
- 使用 jQuery.i18n.properties 实现 Web 前端的国际化
- 使用 jQuery.i18n.properties 实现Web 前端的国际化
- 使用 jQuery.i18n.properties 实现Web 前端的国际化
- 使用 jQuery.i18n.properties 实现 Web 前端的国际化
- 基于jQuery.i18n.properties 实现前端页面的资源国际化
- 使用 jQuery.i18n.properties 实现 Web 前端的国际化
- 使用 jQuery.i18n.properties 实现 Web 前端的国际化
- C++中堆和栈的介绍
- python爬虫
- Unable to load native-hadoop library spark-cluster模式相关错误
- 算法导论之动态规划之最大子数组
- nginx搭建图片服务器
- jquery-i18n-properties国际化(最简单案例)
- AdaBoost(Adaptive Boosting 自适应提升)算法
- java多线程通信方法
- 监听器开始线程执行的方法
- javascript里function之前加上感叹号 ' ! ' 会怎么样?
- 梯度下降法与正规方程法
- 搭建Android开发环境(Eclipse+SDK+ADT)
- 第一个只出现一次的字符
- 我理解中的“大前端”/“大无线”