Class: TranslationIO::Client::BaseOperation::UpdatePotFileStep

Inherits:
Object
  • Object
show all
Defined in:
lib/translation_io/client/base_operation/update_pot_file_step.rb

Instance Method Summary collapse

Constructor Details

#initialize(pot_path, source_files) ⇒ UpdatePotFileStep

Returns a new instance of UpdatePotFileStep.



5
6
7
8
9
10
11
12
13
# File 'lib/translation_io/client/base_operation/update_pot_file_step.rb', line 5

def initialize(pot_path, source_files)
  @pot_path = pot_path

  if TranslationIO.config.disable_gettext
    @source_files = empty_source_files
  else
    @source_files = source_files + Dir['tmp/translation/*.rb']
  end
end

Instance Method Details

#run(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/translation_io/client/base_operation/update_pot_file_step.rb', line 15

def run(params)
  TranslationIO.info "Updating POT file."

  FileUtils.mkdir_p(File.dirname(@pot_path))

  # for gettext >= 3.4.3 (erubi compatibility)
  if defined?(GetText::ErubiParser)
    GetText::Tools::XGetText.run(
      *@source_files, '-o', @pot_path,
      '--msgid-bugs-address', TranslationIO.config.pot_msgid_bugs_address,
      '--package-name',       TranslationIO.config.pot_package_name,
      '--package-version',    TranslationIO.config.pot_package_version,
      '--copyright-holder',   TranslationIO.config.pot_copyright_holder,
      '--copyright-year',     TranslationIO.config.pot_copyright_year.to_s,
      '--require',            'gettext/tools/parser/erubi', # Cf. (1) https://github.com/ruby-gettext/gettext/pull/91
      '--parser',             'GetText::ErubiParser'        #     (2) https://github.com/ruby-gettext/gettext/commit/0eb06a88323a5cc16065680ffe228d978fb87c88
    )
  else
    GetText::Tools::XGetText.run(
      *@source_files, '-o', @pot_path,
      '--msgid-bugs-address', TranslationIO.config.pot_msgid_bugs_address,
      '--package-name',       TranslationIO.config.pot_package_name,
      '--package-version',    TranslationIO.config.pot_package_version,
      '--copyright-holder',   TranslationIO.config.pot_copyright_holder,
      '--copyright-year',     TranslationIO.config.pot_copyright_year.to_s
    )
  end

  FileUtils.rm_f(@tmp_empty_file) if @tmp_empty_file.present?

  params['pot_data'] = File.read(@pot_path)
end