Module: I18n::Tasks::Ar::Attribute
- Defined in:
- lib/i18n/tasks/ar/attribute.rb
Class Method Summary collapse
-
.final_hash(lang) ⇒ Object
Generate final hash with translatable structure.
-
.hash ⇒ Object
Generate hash with models and attributes transformed into i18n structure.
-
.names ⇒ Object
Load classes and attributes and transform them into tash.
Class Method Details
.final_hash(lang) ⇒ Object
Generate final hash with translatable structure
Attribute.final_hash('en') # => { 'en' => { 'activerecord' => { 'attributes' => { ... } } } }
45 46 47 48 49 |
# File 'lib/i18n/tasks/ar/attribute.rb', line 45 def final_hash lang result = {} result[lang.to_s] = { 'activerecord' => { 'attributes' => hash } } result end |
.hash ⇒ Object
Generate hash with models and attributes transformed into i18n structure
Attribute.hash # => { 'my_model/subclass' => { 'id' => 'ID', 'attribute_name' => 'Attribute name' } }
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/i18n/tasks/ar/attribute.rb', line 24 def hash if !names.empty? result = {} names.each do |key, value| hash_name = Model.slashed(key) result[hash_name] = {} value.each do |attribute| result[hash_name].merge!({ attribute => attribute.gsub('_', ' ').capitalize }) end end result end end |
.names ⇒ Object
Load classes and attributes and transform them into tash
Attribue.names # => { 'MyClass' => ['first_attribute', 'second_attribute'] }
11 12 13 14 15 16 17 |
# File 'lib/i18n/tasks/ar/attribute.rb', line 11 def names result = {} ActiveRecord::Base.descendants.each do |model| result[model.name] = model.attribute_names end result end |