Class: Translatomatic::Translator::MyMemory

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/translator/my_memory.rb

Overview

Interface to the MyMemory translation API

Instance Attribute Summary

Attributes inherited from Base

#listener

Instance Method Summary collapse

Methods inherited from Base

#languages, #name, #translate

Constructor Details

#initialize(options = {}) ⇒ MyMemory

Create a new MyMemory translator instance



16
17
18
19
20
21
22
23
# File 'lib/translatomatic/translator/my_memory.rb', line 16

def initialize(options = {})
  super(options)
  @key = options[:mymemory_api_key] || ENV["MYMEMORY_API_KEY"]
  @email = options[:mymemory_email] || ENV["MYMEMORY_EMAIL"]
  @query_options = {}
  @query_options.merge!(de: @email) if @email
  @query_options.merge!(key: @key) if @key
end

Instance Method Details

#upload(tmx) ⇒ void

This method returns an undefined value.

Upload a set of translations to MyMemory

Parameters:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/translatomatic/translator/my_memory.rb', line 33

def upload(tmx)
  request = Translatomatic::HTTPRequest.new(UPLOAD_URL)
  request.start do |http|
    body = [
      request.file(key: :tmx, filename: "import.tmx",
        content: tmx.to_xml, mime_type: "application/xml"
      ),
      request.param(key: :private, value: 0)
    ]
    response = request.post(body, multipart: true)
    log.debug(t("translator.share_response",
      response: response.body.inspect))
  end
end