google-code-export / globalite

Automatically exported from code.google.com/p/globalite
1 stars 0 forks source link

ActiveRecord error messages still have some English text #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
<%= error_messages_for :user %>

and this is the result

7 errors prohibited this user from being saved

There were problems with the following fields:

    * Password confirmation è richiesto
    * Password è troppo corto (minimo 4 caratteri)
    * Password è richiesto
    * Login è troppo corto (minimo 3 caratteri)
    * Login è richiesto
    * Email è troppo corto (minimo 3 caratteri)
    * Email è richiesto

Original issue reported on code.google.com by mattAimo...@gmail.com on 8 Jul 2007 at 5:27

GoogleCodeExporter commented 9 years ago
I had the same problem, and I found a post somewhere that suggested a solution. 
The 
code below is quick and dirty, maybe someone might want to clean it and put it 
into 
a future version?

module ActionView #nodoc
  module Helpers
    module ActiveRecordHelper
      def error_messages_for(object_name, options = {})
        options = options.symbolize_keys
        object = instance_variable_get("@#{object_name}")
        unless object.errors.empty?
          ding = ""
          object.errors.each { |attr, msg| ding += "<li>" + trs(attr) + " " + msg + 
"</li>" }
          content_tag("div",
          content_tag(
                      options[:header_tag] || "h2",
              "#{object.errors.count} #{:error_messages_for_heading.l}" 
          ) +
          content_tag("p", "#{:error_messages_for_fields.l}") +
          content_tag("ul", ding),
            "id" => options[:id] || "errorExplanation", "class" => options[:class] |
| "errorExplanation" 
          )
        end
      end

      private
      def trs(fld)
        # a better solution for this would be very nice
        fieldtrans = {"city" => "sted", 
                  "zip" => "postnummer", 
                  "firstname" => "fornavn",
                  "lastname" => "etternavn", 
                  "phone" => "telefon",
                  "address" => "adresse",
                  "email" => "epost"}
         (fieldtrans[fld] || fld).capitalize
      end
    end
  end
end

Put this in /app/overrides/active_record/errors.rb

/app/overrides/all.rb contains:
# all.rb

Dir[File.dirname(__FILE__) + "/**/*.rb"].each { |file| require(file) }

and /config/environment.rb contains the line:
require "#{RAILS_ROOT}/app/overrides/all"

It is ugly, but it works... (of course not with other types of fields that the 
ones 
that are handcoded here. Should do something where you could specify something 
like 

key_zip: Postnummer
key_phone: Telefon
...

in your globallite /lang/ui/[lang].yml file... 

Then in 

Original comment by anders.s...@gmail.com on 3 Aug 2007 at 11:11

GoogleCodeExporter commented 9 years ago
problem fixed in revision 70

Original comment by mattAimo...@gmail.com on 2 Sep 2007 at 6:41