Skip to content

Commit

Permalink
Scope messages under additional translation key.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaHydrae committed Jan 23, 2015
1 parent 8de4167 commit 087dc14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/errapi/plugins/i18n_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class Errapi::Plugins::I18nMessages
def serialize_error error, serialized
return if serialized.key? :message

if I18n.exists? error.reason
if I18n.exists? translation_key = "errapi.#{error.reason}"
interpolation_values = INTERPOLATION_KEYS.inject({}){ |memo,key| memo[key] = error.send(key); memo }.reject{ |k,v| v.nil? }
serialized[:message] = I18n.t error.reason, interpolation_values
serialized[:message] = I18n.t translation_key, interpolation_values
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/errapi/validation_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def clear
@data = OpenStruct.new
end

# TODO: add custom serialization options
def serialize
# TODO: add hook for plugins to serialize context
{ errors: [] }.tap do |h|
Expand Down
17 changes: 9 additions & 8 deletions locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
en:
missing: "This value is required."
"null": "This value cannot be null."
empty: "This value cannot be empty."
blank: "This value cannot be blank."
too_long: "This value is too long (the maximum is %{check_value} while the actual length is %{checked_value})."
too_short: "This value is too short (the maximum is %{check_value} while the actual length is %{checked_value})."
wrong_length: "This value is the wrong length (the expected length is %{check_value} while the actual length is %{checked_value}."
wrong_type: "This value is of the wrong type."
errapi:
missing: "This value is required."
"null": "This value cannot be null."
empty: "This value cannot be empty."
blank: "This value cannot be blank."
too_long: "This value is too long (the maximum is %{check_value} while the actual length is %{checked_value})."
too_short: "This value is too short (the maximum is %{check_value} while the actual length is %{checked_value})."
wrong_length: "This value is the wrong length (the expected length is %{check_value} while the actual length is %{checked_value}."
wrong_type: "This value is of the wrong type."

0 comments on commit 087dc14

Please sign in to comment.