Sha256: 5f31bbcae1ce4be4a28402d30330290acd70b41f4f3426b6aebf81ebc6de8573

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

require 'gettext_i18n_rails/gettext_hooks'

module GettextI18nRails
  class BaseParser
    def self.target?(file)
      File.extname(file) == ".#{extension}"
    end

    def self.parse(file, _options = {}, msgids = [])
      return msgids unless load_library
      code = convert_to_code(File.read(file))
      RubyGettextExtractor.parse_string(code, msgids, file)
    rescue Racc::ParseError => e
      $stderr.puts "file ignored: ruby_parser cannot read #{extension} files with 1.9 syntax --- #{file}: (#{e.message.strip})"
      return msgids
    end

    def self.libraries
      [extension]
    end

    def self.load_library
      return true if @library_loaded

      loaded = libraries.detect do |library|
        if Gem::Specification.find_all_by_name(library).any?
          require library
          true
        else
          false
        end
      end

      unless loaded
        puts "No #{extension} library could be found: #{libraries.join(" or ")}"

        return false
      end

      require 'gettext_i18n_rails/ruby_gettext_extractor'
      @library_loaded = loaded
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gettext_i18n_rails-1.11.0 lib/gettext_i18n_rails/base_parser.rb
gettext_i18n_rails-1.10.1 lib/gettext_i18n_rails/base_parser.rb
gettext_i18n_rails-1.10.0 lib/gettext_i18n_rails/base_parser.rb
gettext_i18n_rails-1.9.0 lib/gettext_i18n_rails/base_parser.rb
gettext_i18n_rails-1.8.1 lib/gettext_i18n_rails/base_parser.rb
gettext_i18n_rails-1.8.0 lib/gettext_i18n_rails/base_parser.rb
gettext_i18n_rails-1.7.2 lib/gettext_i18n_rails/base_parser.rb