29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'common/jsonmodel_i18n_mixin.rb', line 29
def translate_exception_message(msg, path = nil)
if path == 'conflicting_record'
return t("validation_errors.conflicting_record", {:record_uri => msg})
end
msg_data = case msg
when "Can't be empty"
[:cant_be_empty]
when "entered value didn't match password"
[:password_did_not_match]
when "Group code must be unique within a repository"
[:group_code_already_in_use]
when "Property is required but was missing"
[:missing_required_property]
when "Property was missing"
[:missing_property]
when "Not a valid date", "not a valid date"
[:not_a_valid_date]
when "is required unless a begin or end date is given"
[:is_required_unless_a_begin_or_end_date_is_given]
when "is required unless an expression or an end date is given"
[:is_required_unless_an_expression_or_an_end_date_is_given]
when "That ID is already in use"
[:id_already_in_use]
when /^Username '(.+)' is already in use/
[:username_already_in_use, {:username => $1}]
when /^Did not match regular expression: (.+)/
[:did_not_match_regular_expression, {:regexp => $1}]
when /^Must be at least ([0-9]+) characters/
[:too_few_characters, {:min_length => $1}]
when /^Must be ([0-9]+) characters or fewer/
[:too_many_characters, {:max_length => $1}]
when /^At least ([0-9]+) item\(s\) is required/
[:too_few_items, {:min_items => $1}]
when /^Invalid value '(.*?)'. Must be one of: (.*)/
[:invalid_value, {:value => $1, :valid_set => $2}]
when /^Must be a (.*?) \(you provided a (.*)\)/
[:wrong_type, {:desired_type => $1, :actual_type => $2}]
when /^Must be one of: (.*?) \(you provided a (.*)\)/
[:must_be_one_of, {:allowed_types => $1, :actual_type => $2}]
when /Username '(.*)' is already in use/
[:username_already_in_use, {:username => $1}]
else
[msg.to_s.downcase.gsub(/[\s,':]/, '_')]
end
key, vars = *msg_data
t("validation_errors.#{key.to_s}", vars)
end
|