我有ajax设计表单,在错误追加字段和错误消息到表单底部。
关于ajax:错误我做了以下事情:
$.each(errors, function(field, messages){
error_div.append(field + " " + "messages)
});
我想翻译发送的错误以及设计生成的消息我找到了对我有用的答案(在我的翻译文件中添加):
en:
errors:
messages:
accepted: "have to be checked"
现在当我收到错误时,就像是:
必须检查terms_and_conditions
因此我的列表中的下一步是以某种方式翻译这些模态属性
所以我发现另一个SO帖子解释了一种翻译模型属性的方法,如下所示:
activerecord:
models:
recruiter:
terms_and_conditions: "Terms and conditions"
但我收到501服务器错误, 跟踪错误并打印错误后,如下所示:
I18n::InvalidPluralizationData at /recruiters
=============================================
> translation data {:terms_and_conditions=>"TERMS TRANSLATION"} can not be used with :count => 1
app/controllers/recruiters/registrations_controller.rb, line 8
``` ruby
3
4 def create
5 respond_to do |format|
6 format.json {
7 build_resource(sign_up_params)
> 8 if resource.save
9 RegistrationMailer.recruiter(resource.id).deliver_later! if Rails.env.production?
10 sign_in(resource_name, resource)
11 if ['true', true].include?(params[:get_token])
12 token = resource.generate_authentication_token!
13 render json: { id: resource.id, email: resource.email, authentication_token: token }
所以我找了错误InvalidPluralizationData并找到了解释你需要单数和复数翻译的答案。 所以我改变了我试过
activerecord:
models:
recruiter:
terms_and_conditions:
one: "Term and condition singular test"
other: "Term and conditions plural test"
但同样的错误仍然适用于不同的参数:
translation data {:company_name=>{:one=>"Term and condition singular test", :other=>"Term and conditions plural test"}} can not be used with :count => 1
我还没有找到合适的解决方案来翻译这些模型属性而不会破坏整个表单(即使我尝试翻译属性,我也无法提交表单)。
非常感谢任何帮助。