class TranslationIO::Client::BaseOperation::DumpMarkupGettextKeysStep
Public Class Methods
new(markup_source_files, markup_type)
click to toggle source
# File lib/translation_io/client/base_operation/dump_markup_gettext_keys_step.rb, line 5 def initialize(markup_source_files, markup_type) @markup_source_files = markup_source_files @markup_type = markup_type end
Public Instance Methods
run()
click to toggle source
# File lib/translation_io/client/base_operation/dump_markup_gettext_keys_step.rb, line 10 def run if @markup_source_files.any? TranslationIO.info "Extracting Gettext entries from #{@markup_type.to_s.upcase} files." FileUtils.mkdir_p(File.join('tmp', 'translation')) extracted_gettext_entries.each_with_index do |entry, index| file_path = File.join('tmp', 'translation', "#{@markup_type}-gettext-#{index.to_s.rjust(8,'0')}.rb") File.open(file_path, 'w') do |file| file.puts "def fake" file.puts " #{entry}" file.puts "end" end # can happen sometimes if gettext parsing is wrong if ruby_cmd_available? remove_file_if_syntax_invalid(file_path, entry) end end end end
Protected Instance Methods
extracted_gettext_entries()
click to toggle source
# File lib/translation_io/client/base_operation/dump_markup_gettext_keys_step.rb, line 47 def extracted_gettext_entries entries = [] @markup_source_files.each do |markup_file_path| TranslationIO.info markup_file_path, 2, 2 markup_data = File.read(markup_file_path) entries += TranslationIO::Extractor.extract(markup_data) end TranslationIO.info "#{entries.size} entries found", 2, 2 entries end
remove_file_if_syntax_invalid(file_path, entry)
click to toggle source
# File lib/translation_io/client/base_operation/dump_markup_gettext_keys_step.rb, line 35 def remove_file_if_syntax_invalid(file_path, entry) if `ruby -c #{file_path} 2>/dev/null`.empty? # returns 'Syntax OK' if syntax valid TranslationIO.info "" TranslationIO.info "Warning - #{@markup_type.to_s.upcase} Gettext parsing failed: #{entry}" TranslationIO.info " This entry will be ignored until you fix it. Please note that" TranslationIO.info " this warning can sometimes be caused by complex interpolated strings." TranslationIO.info "" FileUtils.rm(file_path) end end
ruby_cmd_available?()
click to toggle source
# File lib/translation_io/client/base_operation/dump_markup_gettext_keys_step.rb, line 62 def ruby_cmd_available? @ruby_cmd_available ||= `which ruby`.strip.length > 0 end