这篇文章主要介绍了怎么基于jQuery.i18n实现web前端的国际化的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇怎么基于jQuery.i18n实现web前端的国际化文章都会有所收获,下面我们一起来看看吧。
1.首先,建立资源文件:
locales/en-us/ns.jsp.json:
{ "reSendMail": { "emailSendFail": "Failed to send the email", "emailHasSendToYourEmail": "The email has be sent to your email address. " }, "login": { "pleaseWriteUserName": "Please input your username", "pleaseWritePassword": "Please input your password " }, "activeRegist": { "thisUserEmailHasUsed":"Email has already been used", "thisUserNameHasUsed":"User Name has already been used", "4to30Char":"Please enter 4-30 characters", "1to50Char":"Please enter 1-50 characters", "1to16Linkman":"Please enter 1-16 characters", "loginPage":"Login Page", "EmailMustNotEmpty": "Email can't be blank", "PWDNotEmpty": "Password can't be blank", "nameNotEmpty":"Name can't be blank", "conpanyNotEmpty":"Company can't be blank", "qqNotEmpty":"QQ can not be blank", "phoneNotEmpty":"Mobile can not be blank", "least50charEmailAddress":"No more than 50 characters for email address", "enterEmailAddressLikeThis":"Email address format 'abc@abc.com'", "enter6To32Character":"Please enter 6-32 characters", "NameMost30Character":"No more than 30 characters for name", "QQTypeIsWrong":"Incorrent QQ format", "phoneTypeNotCorrect":"Incorrent mobile format", "thisEmailHasRegistered":"Email address has already been registered", "registerFail":"Registration failed!", "TwoTimesPWDIsDifferent":"The passwords you entered do not match. Please try again." } }
中文配置文件就不写了,格式一样,用了map的形式份模块来写。
2.在jsp页面上引入i18n.js并初始化i18n
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="js/i18next.js"></script> <script type="text/javascript"> i18n.init({ lng:'${sessionScope.language }', ns: { namespaces: ['ns.jsp'], defaultNs: 'ns.jsp'}, useLocalStorage: false }); </script>
3.js引用
var emailflag = false; function checkemail() { check('email', 'emailmessage'); var email = $("#email").attr("value"); if(email != null && email != "") { if(email.length > 50) { setDivInfo("emaildiv", i18n.t('activeRegist.least50charEmailAddress'), 1);//请输入50字符内的邮箱地址 } else { if(isEmail(email, $("#email"))) { checkemailForServer(email); } else { setDivInfo("emaildiv", i18n.t('activeRegist.enterEmailAddressLikeThis'), 1);//请输入邮箱地址,格式为abc@abc.com } } } }
4.测试
关于“怎么基于jQuery.i18n实现web前端的国际化”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“怎么基于jQuery.i18n实现web前端的国际化”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。