class Locca::TranslateAction
Public Class Methods
new(project, lang, collection_builder, collection_writer, collection_merger)
click to toggle source
# File lib/locca/actions/translate_action.rb, line 30 def initialize(project, lang, collection_builder, collection_writer, collection_merger) @project = project @lang = lang @collection_merger = collection_merger @collection_builder = collection_builder @collection_writer = collection_writer end
Public Instance Methods
execute()
click to toggle source
# File lib/locca/actions/translate_action.rb, line 38 def execute() editor = ENV['EDITOR'] if !editor raise ArgumentError, 'EDITOR variable should be defined' end @project.collection_names().each do |collection_name| collection_path = @project.path_for_collection(collection_name, @lang) collection = @collection_builder.collection_at_path(collection_path) tmpCollection = Collection.new() collection.sorted_each do |item| if item.translated? next end tmpCollection.add_item(item) end if tmpCollection.count == 0 next end tmpFile = Tempfile.new("#{collection_name}.#{@lang}.tmp") @collection_writer.write_to_path(tmpCollection, tmpFile.path) command = "#{editor} #{tmpFile.path}" stdout,stderr,status = Open3.capture3(command) if status.success? translated_collection = @collection_builder.collection_at_path(tmpFile.path) @collection_merger.merge(translated_collection, collection, (CollectionMerger::ACTION_UPDATE)) @collection_writer.write_to_path(collection, collection_path) end tmpFile.close tmpFile.unlink end end