Created
April 6, 2013 16:35
-
-
Save lastcanal/5326707 to your computer and use it in GitHub Desktop.
Adds Ohm model errors to padrino admin locales.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
$mapping = { | |
format: :invalid, | |
not_present: :blank, | |
not_numeric: :not_a_number, | |
not_url: :invalid, | |
not_email: :invalid, | |
not_valid: :inclusion, | |
not_in_range: :inclusion, | |
not_decimal: :invalid | |
} | |
Dir.glob('*.yml').each do |filename| | |
yaml = YAML.load_file(filename) | |
ar_messages = yaml[yaml.keys.first]["activemodel"]["errors"]["messages"] | |
messages = $mapping.inject({}) do |messages, (ohm, ar)| | |
messages[ohm] = ar_messages[ar.to_s] | |
messages | |
end | |
File.open(filename, 'a') do |file| | |
file.puts <<-YAML | |
ohm: | |
errors: | |
messages: | |
YAML | |
indent = ' ' * 8 | |
messages.each_pair do |key, value| | |
file.puts indent + "#{key}: \"#{value}\"" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment