Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#436 Validators is not localized #439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ en:
api_documentation: API documentation
headers: Headers
header_name: Header name
must_be: "Must be %{string}"
must_be_one_of: "Must be one of: %{string}."
must_be_an_array_of: "Must be one of: %{string}."
must_be_a_number: Must be a number
must_be_a_hash: Must be a Hash
must_be_true_or_false: Must be 'true' or 'false' or '1' or '0'
must_be_an_array_of_nested_elements: Must be an Array of nested elements
16 changes: 8 additions & 8 deletions lib/apipie/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def self.build(param_description, argument, options, block)
end

def description
"Must be #{@type}"
I18n.t 'apipie.must_be', :string => @type, default: 'Must be %{string}'
end

def expected_type
Expand Down Expand Up @@ -150,7 +150,7 @@ def self.build(param_description, argument, options, proc)

def description
string = @array.map { |value| "<code>#{value}</code>" }.join(', ')
"Must be one of: #{string}."
I18n.t 'apipie.must_be_one_of', :string => string, default: 'Must be one of: %{string}.'
end
end

Expand All @@ -173,7 +173,7 @@ def process_value(values)
end

def description
"Must be an array of #{items}"
I18n.t 'apipie.must_be_an_array_of', :string => items, default: 'Must be an array of %{string}'
end

def expected_type
Expand Down Expand Up @@ -243,7 +243,7 @@ def self.build(param_description, argument, options, block)
end

def description
"Must be one of: #{@array.join(', ')}."
I18n.t 'apipie.must_be_one_of', :string => @array.join(', '), default: 'Must be one of: %{string}.'
end
end

Expand Down Expand Up @@ -327,7 +327,7 @@ def process_value(value)
end

def description
"Must be a Hash"
I18n.t 'apipie.must_be_a_hash', default: 'Must be a Hash'
end

def expected_type
Expand Down Expand Up @@ -388,7 +388,7 @@ def self.build(param_description, argument, options, block)
end

def description
"Must be a number."
I18n.t 'apipie.must_be_a_number', default: 'Must be a number'
end

def self.validate(value)
Expand All @@ -413,7 +413,7 @@ def expected_type
end

def description
"Must be 'true' or 'false' or '1' or '0'"
I18n.t 'apipie.must_be_true_or_false', default: "Must be 'true' or 'false' or '1' or '0'"
end
end

Expand Down Expand Up @@ -454,7 +454,7 @@ def expected_type
end

def description
"Must be an Array of nested elements"
I18n.t 'apipie.must_be_an_array_of_nested_elements', default: 'Must be an Array of nested elements'
end

def params_ordered
Expand Down