Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the internationalization of web Front end based on jQuery.i18n

Shulou Source: shulou.com Published: 2022-06-01 02:16:18 09月15日 Update

这篇文章主要介绍了怎么基于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

i18n.init({ lng:'${sessionScope.language }', ns: { namespaces: ['ns.jsp'], defaultNs: 'ns.jsp'}, useLocalStorage: false });

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前端的国际化"知识都有一定的了解,大家如果还想学习更多知识,欢迎关注行业资讯频道。

Tags: Front end international knowledge content address file format article mailbox input value character form easy to operate article easy to understand more module look industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn Docker Shulou Tech Info MySQL