dm-validations-i18n 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/dm-validations-i18n.gemspec +2 -2
- data/lib/dm-validations-i18n.rb +6 -1
- data/test/test_dm-validations-i18n.rb +8 -10
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/dm-validations-i18n.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-validations-i18n}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Masaki KOMAGATA"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-07}
|
13
13
|
s.description = %q{Localize error messages in dm-validations.}
|
14
14
|
s.email = %q{komagata@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/dm-validations-i18n.rb
CHANGED
@@ -79,7 +79,12 @@ end
|
|
79
79
|
class DataMapper::Validations::ValidationErrors
|
80
80
|
class << self
|
81
81
|
def default_error_message_with_localized_field_name(key, field, *values)
|
82
|
-
|
82
|
+
translator = DataMapper::Validations::I18n.field_name_translator
|
83
|
+
|
84
|
+
if translator
|
85
|
+
field = translator.translate(field)
|
86
|
+
end
|
87
|
+
|
83
88
|
@@default_error_messages[key] % [field, *values].flatten
|
84
89
|
end
|
85
90
|
|
@@ -20,17 +20,15 @@ class TestDmValidationsI18n < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
# context 'localized field names with callback' do
|
24
|
-
# DataMapper::Validations::I18n.translate_field_name_with do |field_name|
|
25
|
-
# assert_equal field_name, 'foo'
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
# context 'localized field names with rails I18n.t' do
|
29
|
-
# # mock I18n.t(field, "dm-validation")
|
30
|
-
# DataMapper::Validations::I18n.translate_field_name_with :rails
|
31
|
-
# end
|
32
|
-
|
33
23
|
context 'DataMapper::Validations::ValidationErrors.default_error_message' do
|
24
|
+
should "not localize field names if not asked to" do
|
25
|
+
# manually set to nil, beacuse this test might not be the first to run.
|
26
|
+
DataMapper::Validations::I18n.field_name_translator = nil
|
27
|
+
|
28
|
+
DataMapper::Validations::I18n.localize!('zh-TW')
|
29
|
+
assert_equal("height 無效", DataMapper::Validations::ValidationErrors.default_error_message(:invalid, :height))
|
30
|
+
end
|
31
|
+
|
34
32
|
should "localize field names with Rails way: I18n.t is used." do
|
35
33
|
# mock I18n.t
|
36
34
|
class ::I18n
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-validations-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Masaki KOMAGATA
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-07 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|