Class: I18nTemplate::Extractor::Plain

Inherits:
Base
  • Object
show all
Defined in:
lib/i18n_template/extractor/plain.rb

Overview

Extract phrases to plain format: Each phrase per line

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from I18nTemplate::Extractor::Base

Class Method Details

.default_optionsObject



14
15
16
17
18
# File 'lib/i18n_template/extractor/plain.rb', line 14

def default_options
  super.merge({
    :output_file => 'phrases.txt'
  })
end

.formatObject



10
11
12
# File 'lib/i18n_template/extractor/plain.rb', line 10

def format
  'plain'
end

Instance Method Details

#call(paths) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/i18n_template/extractor/plain.rb', line 21

def call(paths)
  sources = {}

  paths.each do |path|
    phrases = extract_phrases(path)
    phrases.each do |phrase|
      sources[phrase] ||= []
      sources[phrase] << path 
    end
  end

  log "Extracting #{sources.keys.size} phrases to #{@options[:output_file]}"
  File.open(@options[:output_file], "w") do |f|
    sources.sort.each do |phrase, paths|
      f << "# #{paths.join(",")}\n"
      f << phrase
      f << "\n"
    end
  end
end