module GettextI18nRails

Constants

IGNORE_TABLES
Version

Public Class Methods

store_model_attributes(options) click to toggle source

write all found models/columns to a file where GetTexts ruby parser can find them

# File lib/gettext_i18n_rails/model_attributes_finder.rb, line 6
def store_model_attributes(options)
  file = options[:to] || 'locale/model_attributes.rb'
  begin
    File.open(file,'w') do |f|
      f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
      ModelAttributesFinder.new.find(options).each do |model,column_names|
        f.puts("_('#{model.humanize_class_name}')")

        #all columns namespaced under the model
        column_names.each do |attribute|
          translation = model.gettext_translation_for_attribute_name(attribute)
          f.puts("_('#{translation}')")
        end
      end
      f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
    end
  rescue
    puts "[Error] Attribute extraction failed. Removing incomplete file (#{file})"
    File.delete(file)
    raise
  end
end

Private Instance Methods

store_model_attributes(options) click to toggle source

write all found models/columns to a file where GetTexts ruby parser can find them

# File lib/gettext_i18n_rails/model_attributes_finder.rb, line 6
def store_model_attributes(options)
  file = options[:to] || 'locale/model_attributes.rb'
  begin
    File.open(file,'w') do |f|
      f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
      ModelAttributesFinder.new.find(options).each do |model,column_names|
        f.puts("_('#{model.humanize_class_name}')")

        #all columns namespaced under the model
        column_names.each do |attribute|
          translation = model.gettext_translation_for_attribute_name(attribute)
          f.puts("_('#{translation}')")
        end
      end
      f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
    end
  rescue
    puts "[Error] Attribute extraction failed. Removing incomplete file (#{file})"
    File.delete(file)
    raise
  end
end