如何启用jQuery验证本地化? [英] How to enable jquery validate localization?

查看:81
本文介绍了如何启用jQuery验证本地化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用jquery mobile实现的注册表格.用户可以选择以德语,英语或法语填写此表单-有多个内部页面用于以每种语言显示表单.用户可以通过菜单按钮选择自己喜欢的语言.

I have a registration form implemented using jquery mobile. The user can choose to complete this form in either German, English or French - there are multiple internal pages used to display the form in each language .. The user selects their preferred language via a menu button.

我正在使用jquery validate插件来处理客户端表单验证.这很好..我想知道如何在每种语言页面上为表单启用正确的错误消息吗?当您从github下载插件时,它包含所有本地化错误代码,但我不确定如何启用它..

I'm using the jquery validate plugin to handle client-side form validation. This works fine .. I'm wondering how to enable the right error messages for the form on each language page ? When you download the plugin from github it includes all the localization error code but I'm not sure how to enable it ..

这是我用来处理每种语言页面的表单验证的JavaScript代码.

Here's the JavaScript code I'm using to handle implementing the form validation for each language page ..

感谢您能帮助我为德国& amp;启用正确的错误消息.法语网页..

Thanks if you can help me to enable the right error messages for the German & French pages ..

$(document).on("pageshow", "#page_deutsch", function() {

$("#register_deutsch").validate();

});

$(document).on("pageshow", "#page_english", function() {

$("#register_english").validate();

});

$(document).on("pageshow", "#page_francais", function() {

$("#register_francais").validate();

});

推荐答案

jQuery验证插件本地化 jQuery验证插件的默认语言是英语. 它可以被本地化js文件覆盖,例如. es,zh,fr等 有关支持的语言列表,请此处.

jQuery validation plugin localization The default language for jQuery validation plugin is English. It could be overridden with the localization js file, eg. es, zh, fr, etc. Please refer here for the list of supported languages.

要启用语言支持,我们只需要在我们的网页(html/jsp/xhtml)中添加其他语言消息js. 法语

To enable languages support, we just need to add other language message js into our webpage (html/jsp/xhtml). for french

<script type="text/javascript" src="http://jzaefferer.github.io/jquery-validation/localization/messages_fr.js" />

中文

<script type="text/javascript" src="http://jzaefferer.github.io/jquery-validation/localization/messages_zh.js" />

与其他语言相同,只需找到合适的语言js,然后将js添加到网页中即可.

Same for other languages, just find the appropriate language js and add the js into the webpage.

如果所需的语言不在列表中,则可行的替代方法是将messages_xx.js的副本下载到项目工作区中,然后将其修改为所需的语言.

if the required language is not in the list, an workable alternative is to download a copy of the messages_xx.js into project workspace, then modify it to your required language.

尽管提供了js语言,但问题在于1个网页中我们只能使用1种语言消息.如果网页中使用多种语言的消息js,将使用最后一个.

Although the language js is provided, but the problem is in 1 webpage we can only use 1 type of language message. If multiple language message js in the webpage, the last will be used.

要解决此问题,我们可以通过系统区域设置动态加载消息js.

To resolve this problem, we can dynamically load the messages js by system locale.

<script type="text/javascript" src="http://jzaefferer.github.io/jquery-validation/localization/messages_<%= Locale.getDefault().getLanguage() %>.js" />

使用上述解决方案,最终我们可以根据不同的系统区域设置动态处理不同的语言消息.

with the above solution, finally we can dynamically handle different language message by different system locale.

这里还有另一种使用资源包处理多种语言的方法.

There is another way to handle multiple languages with resource bundle here.

有关jQuery验证的文章:

related jQuery validation articles:

  • 电子邮件
  • 信用卡
  • 多个表单字段
  • 自定义错误消息
  • 在JSF中使用jQuery验证插件
  • 多语言错误消息
  • jQuery验证插件中的错误处理

完成!

这篇关于如何启用jQuery验证本地化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆