-
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.
- add support for custom translations through i18n - adjust default validation error messages to be more ambiguous Closes #12 BREAKING CHANGE: reword default validation error messages
- Loading branch information
Showing
9 changed files
with
148 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'i18n' | ||
|
||
module Limitable | ||
# == Limitable::Locale | ||
# | ||
# Loads the default limitable custom translations into i18n. | ||
# | ||
module Locale | ||
I18n.load_path << File.expand_path('locale/en.yml', __dir__) | ||
end | ||
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,8 @@ | ||
en: | ||
limitable: | ||
integer_limit_exceeded: | ||
upper: "is too large" | ||
lower: "is too small" | ||
string_limit_exceeded: "is too long" | ||
text_limit_exceeded: "is too long" | ||
binary_limit_exceeded: "is too large" |
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'i18n' | ||
require 'limitable/locale' | ||
|
||
RSpec.describe Limitable::Locale do | ||
it 'defines a translation for integers that exceed an upper limit' do | ||
expect { I18n.t! 'limitable.integer_limit_exceeded.upper' }.not_to raise_error | ||
end | ||
|
||
it 'defines a translation for integers that exceed a lower limit' do | ||
expect { I18n.t! 'limitable.integer_limit_exceeded.lower' }.not_to raise_error | ||
end | ||
|
||
it 'defines a translation for strings that exceed a length limit' do | ||
expect { I18n.t! 'limitable.string_limit_exceeded' }.not_to raise_error | ||
end | ||
|
||
it 'defines a translation for text that exceeds a length limit' do | ||
expect { I18n.t! 'limitable.text_limit_exceeded' }.not_to raise_error | ||
end | ||
|
||
it 'defines a translation for binary data that exceeds a size limit' do | ||
expect { I18n.t! 'limitable.binary_limit_exceeded' }.not_to raise_error | ||
end | ||
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
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'i18n' | ||
|
||
I18n.load_path << File.expand_path('locale/test.yml', __dir__) |
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,8 @@ | ||
test: | ||
limitable: | ||
integer_limit_exceeded: | ||
upper: "max integer is %{limit}" | ||
lower: "min integer is %{limit}" | ||
string_limit_exceeded: "max string is %{limit}" | ||
text_limit_exceeded: "max text is %{limit}" | ||
binary_limit_exceeded: "max binary is %{limit}" |