JQuery国际化实现
1、插件
<script type="text/javascript" src="lib/jQuery/jquery-2.2.2.min.js"></script>
<script type="text/javascript" src="lib/jQuery/jquery.i18n.properties-min-1.0.9.js"></script>
jquery.i18n.properties的简介请访问:
http://www.ibm.com/developerworks/cn/web/1305_hezj_jqueryi18n/
2、资源文件
我的路径 /res/strings/
strings_zh.properties //中文
strings_en.properties //英文
strings_de.properties //德文
strings_other.properties //任意一国语言,针对海外本地化配置,只需要将该国的语言资源放入按照 app_clear=清除 的形式放入
//strings_other.properties文件中,并在步骤3中设置_appscope.lang='other',调用setLang()方法即可加载strings_other.properties的资源。
3、读取对应语言的资源文件
/** 设置语言 */
this.setLang=function() {
_appscope.resource = null;
// location.href="#init";
jQuery.i18n.properties({// 加载资浏览器语言对应的资源文件
name : 'strings', // 资源文件名称
language : _appscope.lang, // 默认为英文当改为zh_CN时页面显示中文语言
path : 'res/strings/', // 资源文件路径
mode : 'map', // 用 Map 的方式使用资源文件中的值
callback : function() {// 加载成功后设置显示内容
_appscope.resource = $.i18n.map;
}
});
}
4、获得字符串
_appscope.clear=_appscope.resource.app_clear;
总结:本人是在angularjs框架中结合JQuery在国际化方面的便利来实现web网页的国际化。
1、插件
<script type="text/javascript" src="lib/jQuery/jquery-2.2.2.min.js"></script>
<script type="text/javascript" src="lib/jQuery/jquery.i18n.properties-min-1.0.9.js"></script>
jquery.i18n.properties的简介请访问:
http://www.ibm.com/developerworks/cn/web/1305_hezj_jqueryi18n/
2、资源文件
我的路径 /res/strings/
strings_zh.properties //中文
strings_en.properties //英文
strings_de.properties //德文
strings_other.properties //任意一国语言,针对海外本地化配置,只需要将该国的语言资源放入按照 app_clear=清除 的形式放入
//strings_other.properties文件中,并在步骤3中设置_appscope.lang='other',调用setLang()方法即可加载strings_other.properties的资源。
3、读取对应语言的资源文件
/** 设置语言 */
this.setLang=function() {
_appscope.resource = null;
// location.href="#init";
jQuery.i18n.properties({// 加载资浏览器语言对应的资源文件
name : 'strings', // 资源文件名称
language : _appscope.lang, // 默认为英文当改为zh_CN时页面显示中文语言
path : 'res/strings/', // 资源文件路径
mode : 'map', // 用 Map 的方式使用资源文件中的值
callback : function() {// 加载成功后设置显示内容
_appscope.resource = $.i18n.map;
}
});
}
4、获得字符串
_appscope.clear=_appscope.resource.app_clear;
总结:本人是在angularjs框架中结合JQuery在国际化方面的便利来实现web网页的国际化。