Module: GetText::ActiveRecordParser

### Home Classes Methods

### In Files

- lib/gettext_activerecord/parser.rb

### Methods

- #init
- #translatable_class?
- #translatable_column?

### Included Modules

- GetText

### Class/Module Index

Quicksearch

- ActiveRecord
- ActiveRecord::Base
- ActiveRecord::ConnectionAdapters
- ActiveRecord::ConnectionAdapters::Column
- ActiveRecord::Migration
- GetText
- GetText::ActiveRecordParser
- Class
- GetTextActiveRecord
- Object

No matching classes.

# GetText::ActiveRecordParser

### Public Instance Methods

init(config) click to toggle source

Sets some preferences to parse ActiveRecord files.

- config: a Hash of the config. It can takes some values below:

  - :use_classname - If true, the msgids of ActiveRecord become "ClassName|FieldName" (e.g. "Article|Title"). Otherwise the ClassName is not used (e.g. "Title"). Default is true.

  - :db_yml - the path of database.yml. Default is "config/database.yml".

  - :db_mode - the mode of the database. Default is "development"

  - :activerecord_classes - an Array of the superclass of the models. The classes should be String value. Default is ["ActiveRecord::Base"]

  - :untranslate_classes - an Array of the modules/class names which is ignored as the msgid.

  - :untranslate_columns - an Array of the column names which is ignored as the msgid.

  - :untranslate_table_name - a Boolean that avoids table name to be translated if it is true ... Generally, we don't have to translate table_name, do we? Maybe it is not true..... but it is a test

  - :adapter - the options for ActiveRecord::Base.establish_connection. If this value is set, :db_yml option is ignored.

  - :host - ditto

  - :username - ditto

  - :password - ditto

  - :database - ditto

  - :socket - ditto

  - :encoding - ditto

"ClassName|FieldName" uses GetText.sgettext. So you don't need to translate the left-side of "|". See <Documents for Translators for more details(www.yotabanana.com/hiki/ruby-gettext-translate.html)>.

    # File lib/gettext_activerecord/parser.rb, line 82
    def init(config)
      puts "\nconfig: #{config.inspect}\n\n" if $DEBUG
      if config
        config.each{|k, v|
          @config[k] = v
        }
      end
      @ar_re = /class.*(#{@config[:activerecord_classes].join("|")})/
    end

translatable_class?(klass) click to toggle source

    # File lib/gettext_activerecord/parser.rb, line 92
    def translatable_class?(klass)
      if klass.is_a?(Class) && klass < ActiveRecord::Base
        if klass.untranslate_all? || klass.abstract_class? || @config[:untranslate_classes].include?(klass.name)
          false
        else
          true
        end
      else
        true
      end
    end

translatable_column?(klass, columnname) click to toggle source

    # File lib/gettext_activerecord/parser.rb, line 104
    def translatable_column?(klass, columnname)
      ! (klass.untranslate?(columnname) || @config[:untranslate_columns].include?(columnname))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.