Hi, On Fri, 8 May 2009 19:03:12 -0400 mateo murphy <mateo.mur...@gmail.com> wrote:
> > > > I'm not sure I can find your Github account. If you already have a > > Rails fork and can't use that for some reason please let me know. I'll > > update my fork and add you then. > > > > I've got a rails fork at http://github.com/mateomurphy/rails/tree/master, > however I've yet to make modifications to it, as I'm still trying some > things out. > > Two conclusions so far: > > 1) The string concatenation issue can easily be saved by modifying > full_messages: > > --- a/activerecord/lib/active_record/validations.rb > +++ b/activerecord/lib/active_record/validations.rb > @@ -206,7 +206,7 @@ module ActiveRecord > full_messages << message > else > attr_name = @base.class.human_attribute_name(attr) > - full_messages << attr_name + > I18n.t('activerecord.errors.format.separator', :default => ' ') + message > + full_messages << > I18n.t('activerecord.errors.format.full_message', :default => '{{attribute}} > {{message}}', :attribute => attr_name, :message => message) > end > end > end > That way you can set :activerecord.errors.format.full_message in non english > locales to simply "{{message}}" bypassing concatenation, and it also > provides more flexibility in english than what is provided by simply > modifiying the seperator, which makes it a win-win for everybody > > 2) Deferring the translation of messages will require storing the options > passed to errors.add, as these are used by generate_message. This means that > errors need to be stored either as a hash, or as an object; I think the > latter makes more sense. Thoughts? Yes. gettext_activerecord hacks to pass a options as a hash to errors.add. #I prefer hash because it may be able to increase the parameter easily. Anyway, 'activerecord.errors.format.full_message' seems not good. For example, I may want to replace it unless {{attribute}} with validates_length_of,but want to include {{attribute}} into validates_presence_of. So this should be changed in each messages. class Person < ActiveRecord::Base validates_acceptance_of :foo, :message => "Don't accept it!" # Don't need attribute. validates_length_of :name, :maximum=>30, :message=> "{{attribute}} is less than {{count}}" end And if "message" becomes hash/object, the default value of '{{attribute}} {{message}}' doesn't work well, because count/value can't be handled. + full_messages << I18n.t('activerecord.errors.format.full_message', :default => '{{attribute}} {{message}}', :attribute => attr_name, :message => message, :count => count, # Can't handle this. :value => value) # Can't handle this. So, it should be like as: # obj is an sample with options full_messages << I18n.t(obj["message"], # message or key such as "activerecords....invalid", :attribute => attr_name, :count => obj["count"], # Apply to message :value => obj["value"]) # Can't handle this. Or more general way like as: full_messages << I18n.t(obj["message"], obj) This way make "additional validation helper" can handle their own values. The issue is how to set the default value. # In gettext, it is fallback to the message in the default locale(en). -- Masao Mutoh <mutom...@gmail.com> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "rails-i18n" group. To post to this group, send email to rails-i18n@googlegroups.com To unsubscribe from this group, send email to rails-i18n+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rails-i18n?hl=en -~----------~----~----~----~------~----~------~--~---