dm-validations-i18n 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -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.0"
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-06}
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 = [
@@ -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
- field = DataMapper::Validations::I18n.field_name_translator.translate(field)
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
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-06 00:00:00 +09:00
18
+ date: 2010-10-07 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency