Class: Locomotive::Mounter::Writer::Api::TranslationsWriter

Inherits:
Base
  • Object
show all
Defined in:
lib/locomotive/mounter/writer/api/translations_writer.rb

Overview

Push translations to a remote LocomotiveCMS engine.

Instance Attribute Summary

Attributes inherited from Base

#mounting_point, #runner

Instance Method Summary collapse

Methods inherited from Base

#absolute_path, #data?, #each_locale, #get, #initialize, #path_to_file, #post, #put, #replace_content_assets!, #safe_attributes

Constructor Details

This class inherits a constructor from Locomotive::Mounter::Writer::Api::Base

Instance Method Details

#prepareObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/locomotive/mounter/writer/api/translations_writer.rb', line 10

def prepare
  super

  # set the unique identifier to each local translation
  (self.get(:translations, nil, true) || []).each do |attributes|
    translation = self.translations[attributes['key']]

    translation._id = attributes['id'] if translation
  end
end

#writeObject

Write all the translations to the remote destination



22
23
24
25
26
27
28
29
30
31
# File 'lib/locomotive/mounter/writer/api/translations_writer.rb', line 22

def write
  self.translations.each do |key, translation|
    self.output_resource_op translation

    status = translation.persisted? ? self.update_translation(translation) : self.create_translation(translation)

    self.output_resource_op_status translation, status
    self.flush_log_buffer
  end
end