Class: I18nTemplate::Runner::ExtractPhrases

Inherits:
Base
  • Object
show all
Defined in:
lib/i18n_template/runner/extract_phrases.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Class Method Details

.add_options!(parser, options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/i18n_template/runner/extract_phrases.rb', line 25

def add_options!(parser, options)
  formats = I18nTemplate.extractors.map { |klass| klass.format }

  parser.on(
    "--format #{formats.join('|')}",
    "translation format (default #{default_options[:format]})"
  ) { |v| options[:format] = v }

  parser.on(
    "--po-root PO ROOT",
    "root directly for po files (default #{default_options[:po_root]})"
  ) { |v| options[:po_root] = v }

  parser.on(
    "--glob GLOB",
    "template files glob (default #{default_options[:glob].join(',')})"
  ) { |v| (options[:glob] ||= []) << v }

  parser.on(
    "--textdomain TEXTDOMAIN",
    "gettext textdomain (default #{default_options[:textdomain]})"
  ) { |v| options[:textdomain] = v }

  parser.on(
    "--output-file FILE",
    "output file (default #{default_options[:output_file]})"
  ) { |v| options[:output_file] = v }

  parser.on(
    "--locales-root DIRECTORY",
    "locales directory (default #{default_options[:locales_root]})"
  ) { |v| options[:locales_root] = v }
end

.commandObject



11
12
13
# File 'lib/i18n_template/runner/extract_phrases.rb', line 11

def command
  'extract_phrases'
end

.default_optionsObject



19
20
21
22
23
# File 'lib/i18n_template/runner/extract_phrases.rb', line 19

def default_options
  @default_options ||= I18nTemplate.extractors.inject({}) { |result, klass|
    result.merge!(klass.default_options)
  }
end

.descriptionObject



15
16
17
# File 'lib/i18n_template/runner/extract_phrases.rb', line 15

def description
  'extract phrases for translations'
end

Instance Method Details

#runObject



60
61
62
63
64
65
66
# File 'lib/i18n_template/runner/extract_phrases.rb', line 60

def run
  paths = Dir[*@options[:glob]]

  extractor = I18nTemplate.extractors.detect { |klass| klass.format == @options[:format] }
  extractor or abort "Unknown extract format: #{@options[:format]}"
  extractor.new(@options).call(paths)
end