Module: GetText::ActiveRecordParser

Defined in:
lib/locale_selector/gettext_tasks.rb

Class Method Summary collapse

Class Method Details

.parse(file, targets = []) ⇒ Object

:nodoc:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/locale_selector/gettext_tasks.rb', line 51

def self.parse(file, targets = []) # :nodoc:
  log "locale_selector specific version of activerecordparser.parse is parsing #{file}"
  GetText.locale = "en"
  begin
    eval(open(file).read, TOPLEVEL_BINDING)
  rescue
    $stderr.puts _("Ignored '%{file}'. Solve dependencies first.") % {:file => file}
    $stderr.puts $!
  end
  loaded_constants = ActiveRecord::Base.active_record_classes_list
  ActiveRecord::Base.reset_active_record_classes_list
  loaded_constants.each do |classname|
    klass = eval(classname, TOPLEVEL_BINDING)
    if klass.is_a?(Class) && klass < ActiveRecord::Base
      log "processing class #{klass.name}"
      unless (klass.untranslate_all? || klass.abstract_class?)
        add_target(targets, file, singularize(klass.table_name.gsub(/_/, " ")))
        unless klass.class_name == classname
          add_target(targets, file, singularize(classname.gsub(/_/, " ").downcase))
        end
        begin
          klass.columns.each do |column|
            unless untranslate_column?(klass, column.name)
              if @config[:use_classname]
                msgid = classname + "|" +  klass.human_attribute_name(column.name)
              else
                msgid = klass.human_attribute_name(column.name)
              end
              add_target(targets, file, msgid)
            end
          end
        rescue
          $stderr.puts _("No database is available.")
          $stderr.puts $!
        end
      end
    end
  end
  if RubyParser.target?(file)
    targets = RubyParser.parse(file, targets)
  end
  targets.uniq!
  targets
end

.singularize(s) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/locale_selector/gettext_tasks.rb', line 42

def self.singularize(s)
  # there seems to be a difference between Rails 2.1.2 and 2.1.0
  if defined?(ActiveSupport::Inflector)
    ActiveSupport::Inflector.singularize(s)
  else
    Inflector.singularize(s)
  end
end