Rails3 I18n: Cannot Override "1 Error Prohibiting Saving This Package:"

When I get errors in the model package, I always see the first line (English = not translated):

1 error prohibited this packet from being saved: Naam Gelieve het veld Naam in te vullen! 

Found translations for error for one field!

So far I have the following in nl.yml

 nl: activemodel: errors: template: header: one: "1 fout voorkwam dat dit %{model} kon bewaard worden" other: "%{count} fouten voorkwamen dat deze %{model} kon bewaard worden" body: "Er waren problemen met de volgende velden:" errors: template: body: "Controleer alstublieft de volgende velden:" header: one: "Kon dit {{model}} object niet opslaan: 1 fout." other: "Kon dit {{model}} niet opslaan: {{count}} fouten." activerecord: errors: template: header: one: "1 fout voorkwam dat dit %{model} kon bewaard worden" other: "%{count} fouten voorkwamen dat deze %{model} kon bewaard worden" body: "Er waren problemen met de volgende velden:" messages: blank: Gelieve het veld %{attribute} in te vullen! models: survey: test packet: woordenlijst user: gebruiker attributes: survey: name: Naam 

If you look at a lot of things on rails-i18n, download them nl.yml, but nothing helps. Does anyone know why this is not working?

I thought this was a possible conflict with other files (I have localization files for two other gems), but deleting them temporarily did not change anything.

Does anyone know how to debug this?

Can I somehow remove the default translation so that I get an error whose translation was not found?

+7
ruby-on-rails-3 internationalization
source share
1 answer

Doh! Find him! Stupid to me!

I forgot that in rails 3 you no longer use error_messages_for , so instead of this in my code of view of the linings was the following code:

  = form_for @packet do |f| -if @packet.errors.any? #errorExplanation %h2= "#{pluralize(@packet.errors.count, "error")} prohibited this packet from being saved:" 

So, it is not surprising that I could not translate this. Aaaaarrrgghh !!

The solution is to use the dynamic-form plugin (which gives you the same functionality as in rails 2.3), or adapt the view accordingly, as I did:

  -if @packet.errors.any? #errorExplanation %h2 - if @packet.errors.count == 1 = t 'activerecord.errors.template.header.one', :model => @packet.class.human_name - else = t 'activerecord.errors.template.header.other', :model => @packet.class.human_name, :count => @packet.errors.count %b= t 'activerecord.errors.template.body' %ul - @packet.errors.full_messages.each do |msg| %li= msg 

But, since we need to do this for every view that possibly has errors, this should go into a partial or use the plugin mentioned above :)

+12
source share

All Articles