Skip to content

Instantly share code, notes, and snippets.

@chewi
Created October 13, 2011 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chewi/1283979 to your computer and use it in GitHub Desktop.
Save chewi/1283979 to your computer and use it in GitHub Desktop.
Make Rails use full sentences in validation messages.
module I18n
module Backend
module Base
protected
def load_file_with_sentences(filename)
load_file_without_sentences(filename).tap do |data|
unless Rails.configuration.paths["config/locales"].expanded.include?(filename)
data.each do |locale, d|
if d and d.key?("errors")
if d["errors"].key?("format")
store_translations locale, { "errors" => { "format" => "%{message}" } }
end
if old = d["errors"]["messages"]
new = old.each_with_object({}) { |(k,v),h| h[k] = "%{attribute} #{v}." if v.is_a?(String) }
store_translations locale, { "errors" => { "messages" => new } }
end
end
end
end
end
end
alias_method_chain :load_file, :sentences
end
end
end
begin
RailsAdmin::FormBuilder
rescue NameError
else
class RailsAdmin::FormBuilder
def errors_for field
field.errors.present? ? @template.content_tag(:span, field.errors.first, :class => 'help-inline') : ''
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment