我已经在rails config语言环境中使用了我需要的所有语言的所有错误消息,因此如何从以下位置更改所需的欧芹(和其他验证器)的默认消息:
这是必填栏
然后如何添加其他语言的消息?
简单 :)
Parsley.addMessage('en', 'required', "something else");
Parsley.addMessage('en', 'maxlength', 'something else max is %s')
Parsley.addCatalog('zh-HANS', {required: "其他的东西"}, true);
这会将新语言“ zh-HANS”添加到目录中,并进行了一次翻译,最后的参数true
说是将Parsley更改为该语言环境,因此,如果您只是填充大量其他本地人,则您会说是false。更改语言环境的专用方法是Parsley.setLocale('zh-HANS')
(如果您正在使用滑轨并有类似情况,请继续阅读。)
关于rails以及将翻译内容转换为javascript,我喜欢使用数据属性,因此,如果I18n.locale是zh-HANS,则我将添加一个具有某些ID的div,例如
%div#parsley-translations{data:{'current-locale'=> I18n.locale, required: I18n.t('forms.errors.required'), 'maxlength'=>I18n.t('forms.errors.maxlength')}}
然后在javascript中
var translationData = $('#parsley-translations').data();
// now use AddLocale with all the keys and values from translationData for the translationData.currentLocale - Will adjust this once I have tested and got it working
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句