Class: ToLocale
- Inherits:
-
Object
- Object
- ToLocale
- Defined in:
- lib/model_to_locale/to_locale.rb
Class Method Summary collapse
Class Method Details
.add_model(model, locale = 'tr') ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/model_to_locale/to_locale.rb', line 18 def self.add_model(model, locale='tr') begin data = YAML::load_file(Rails.root.join('config/locales', "models.#{locale}.yml")) data["#{locale}"]['activerecord']['models']["#{model.downcase}"] = model.capitalize data = add_attributes(data, model, locale) write_to_file(data, locale) rescue create(locale) puts "models.#{locale}.yml file not found. Bu it's created now." end end |
.create(locale = 'tr') ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/model_to_locale/to_locale.rb', line 2 def self.create(locale='tr') models = ActiveRecord::Base.connection.tables.map{|model| model.capitalize.singularize.camelize } data = Hash.new data["#{locale}"] = Hash.new data["#{locale}"]['activerecord'] = Hash.new data["#{locale}"]['activerecord']['models'] = Hash.new data["#{locale}"]['activerecord']['attributes'] = Hash.new models.each do |model| data["#{locale}"]['activerecord']['models']["#{model.downcase}"] = model.capitalize data = add_attributes(data, model, locale) end write_to_file(data, locale) end |