您好,登錄后才能下訂單哦!
這篇文章主要介紹了怎么基于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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。