-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e369678
commit e75b24a
Showing
6 changed files
with
72 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
source "https://rubygems.org" | ||
|
||
group :development do | ||
gem 'i18n', '~> 0.7.0' | ||
gem 'rake', '~> 10.3' | ||
gem 'rspec', '~> 3.1' | ||
gem 'rspec-collection_matchers', '~> 1.1' | ||
gem 'jeweler', '~> 2.0' | ||
gem 'rake-version', '~> 0.4' | ||
gem 'simplecov', '~> 0.9' | ||
gem 'coveralls', '~> 0.7', require: false | ||
gem 'simplecov', '~> 0.9.1' | ||
gem 'coveralls', '~> 0.7.3', require: false | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,17 @@ | ||
class Errapi::Plugins::I18nMessages | ||
MESSAGES = { | ||
array_length: { | ||
wrong_length: 'This array must contain exactly %{check_value} elements but has %{checked_value} elements.', | ||
too_short: 'This array must contain at least %{check_value} elements but has only %{checked_value} elements.', | ||
too_long: 'This array must contain at most %{check_value} elements but has %{checked_value} elements.' | ||
}, | ||
presence: { | ||
nil: 'This value cannot be null.', | ||
empty: 'This value cannot be empty.', | ||
blank: 'This value cannot be blank.' | ||
}, | ||
string_length: { | ||
wrong_length: 'This string must be exactly %{check_value} characters long but has %{checked_value} characters.', | ||
too_short: 'This string must be at least %{check_value} characters long but has only %{checked_value} characters.', | ||
too_long: 'This string must be at most %{check_value} characters long but has %{checked_value} characters.' | ||
}, | ||
type: { | ||
wrong_type: 'This value is of the wrong type.' | ||
} | ||
} | ||
require 'i18n' | ||
|
||
def _disabled_build_error error, context | ||
if !error.message && MESSAGES.key?(error.validation) && message = MESSAGES[error.validation][error.reason] | ||
class Errapi::Plugins::I18nMessages | ||
|
||
%w(check_value checked_value).each do |interpolated| | ||
if error.respond_to? interpolated | ||
message = message.gsub /\%\{#{interpolated}\}/, interpolated | ||
end | ||
end | ||
def serialize_error error, serialized | ||
return if serialized.key? :message | ||
|
||
error.message = message | ||
if I18n.exists? 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 | ||
end | ||
end | ||
|
||
private | ||
|
||
INTERPOLATION_KEYS = %i(check_value checked_value) | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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." |
This file contains 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
This file contains 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