File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def initialize(klass)
14
14
@human = ActiveSupport ::Inflector . humanize ( @element ) . freeze
15
15
@collection = ActiveSupport ::Inflector . tableize ( self ) . freeze
16
16
@partial_path = "#{ @collection } /#{ @element } " . freeze
17
- @i18n_key = self . underscore . to_sym
17
+ @i18n_key = ActiveSupport :: Inflector . underscore ( self ) . tr ( '/' , '.' ) . to_sym
18
18
end
19
19
20
20
# Transform the model name into a more humane format, using I18n. By default,
@@ -28,8 +28,9 @@ def human(options={})
28
28
@klass . respond_to? ( :i18n_scope )
29
29
30
30
defaults = @klass . lookup_ancestors . map do |klass |
31
- klass . model_name . i18n_key
32
- end
31
+ [ klass . model_name . i18n_key ,
32
+ klass . model_name . i18n_key . to_s . tr ( '.' , '/' ) . to_sym ]
33
+ end . flatten
33
34
34
35
defaults << options . delete ( :default ) if options [ :default ]
35
36
defaults << @human
Original file line number Diff line number Diff line change @@ -44,8 +44,9 @@ def lookup_ancestors
44
44
# Specify +options+ with additional translating options.
45
45
def human_attribute_name ( attribute , options = { } )
46
46
defaults = lookup_ancestors . map do |klass |
47
- :"#{ self . i18n_scope } .attributes.#{ klass . model_name . i18n_key } .#{ attribute } "
48
- end
47
+ [ :"#{ self . i18n_scope } .attributes.#{ klass . model_name . i18n_key } .#{ attribute } " ,
48
+ :"#{ self . i18n_scope } .attributes.#{ klass . model_name . i18n_key . to_s . tr ( '.' , '/' ) } .#{ attribute } " ]
49
+ end . flatten
49
50
50
51
defaults << :"attributes.#{ attribute } "
51
52
defaults << options . delete ( :default ) if options [ :default ]
Original file line number Diff line number Diff line change @@ -53,5 +53,15 @@ def test_translated_model_names_with_ancestors_fallback
53
53
I18n . backend . store_translations 'en' , :activemodel => { :models => { :person => 'person model' } }
54
54
assert_equal 'person model' , Child . model_name . human
55
55
end
56
+
57
+ def test_alternate_namespaced_model_attribute_translation
58
+ I18n . backend . store_translations 'en' , :activemodel => { :attributes => { :person => { :gender => { :attribute => 'person gender attribute' } } } }
59
+ assert_equal 'person gender attribute' , Person ::Gender . human_attribute_name ( 'attribute' )
60
+ end
61
+
62
+ def test_alternate_namespaced_model_translation
63
+ I18n . backend . store_translations 'en' , :activemodel => { :models => { :person => { :gender => 'person gender model' } } }
64
+ assert_equal 'person gender model' , Person ::Gender . model_name . human
65
+ end
56
66
end
57
67
You can’t perform that action at this time.
0 commit comments