Sha256: 395db92306f85a6bb2466ff16a5d89c5bd796721f54c5bd67876d4b2aa899a91

Contents?: true

Size: 1018 Bytes

Versions: 50

Compression:

Stored size: 1018 Bytes

Contents

# suppress load warning message
verbose = $VERBOSE
$VERBOSE = nil
require 'gettext/rgettext'
$VERBOSE = verbose

module Ramaze::Tool::Gettext::Parser
  module_function

  TARGETS = Ramaze::Template::ENGINES.values.inject([]) do |exts, list|
    list += exts
  end

  def target?(file)
    TARGETS.include?(File.extname(file)[1..-1])
  end

  def parse(file, ary)
    regex = Ramaze::Tool::Gettext.trait[:regex]
    body = File.read(file)
    body.gsub!(regex) do
      msg = $1
      unless msg.to_s.empty?
        line_number = body[0..(body.index(msg))].split("\n").size
        add_message(ary, msg, file, line_number)
      end
    end
    return ary
  end

  def add_message(ary, msg, file, line_number)
    loc = message_location(file, line_number)
    if value = ary.assoc(msg)
      value << loc
    else
      ary << [msg, loc]
    end
    return ary
  end

  def message_location(file, line_number)
    file + ":line" + line_number.to_s
  end
end

GetText::RGetText.add_parser(Ramaze::Tool::Gettext::Parser)

Version data entries

50 entries across 50 versions & 6 rubygems

Version Path
Pistos-ramaze-2008.09 lib/ramaze/contrib/gettext/parser.rb
Pistos-ramaze-2008.12 lib/ramaze/contrib/gettext/parser.rb
Pistos-ramaze-2009.01 lib/ramaze/contrib/gettext/parser.rb
Pistos-ramaze-2009.02 lib/ramaze/contrib/gettext/parser.rb
Pistos-ramaze-2009.04.08 lib/ramaze/contrib/gettext/parser.rb
Pistos-ramaze-2009.06.12 lib/ramaze/contrib/gettext/parser.rb
clivecrous-ramaze-0.3.9.5 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2008.07 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2008.08 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2008.09 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2008.10 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2008.12 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.01 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.04.01 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.04.08 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.04.18 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.04.22 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.04 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.05.08 lib/ramaze/contrib/gettext/parser.rb
manveru-ramaze-2009.05 lib/ramaze/contrib/gettext/parser.rb