Class: Translatomatic::Provider::MyMemory

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/provider/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

#name, supports_alternative_translations?, supports_no_translate_html?, #to_s, #translate

Constructor Details

#initialize(options = {}) ⇒ MyMemory

Create a new MyMemory provider instance



12
13
14
15
16
17
18
19
# File 'lib/translatomatic/provider/my_memory.rb', line 12

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[:de] = @email if @email
  @query_options.merge!(key: @key) if @key
end

Instance Method Details

#languagesArray<String>

Returns A list of languages supported by this provider.

Returns:

  • (Array<String>)

    A list of languages supported by this provider.



22
23
24
# File 'lib/translatomatic/provider/my_memory.rb', line 22

def languages
  Locale.language_codes
end

#upload(tmx) ⇒ void

This method returns an undefined value.

Upload a set of translations to MyMemory

Parameters:



29
30
31
32
33
34
35
36
37
38
# File 'lib/translatomatic/provider/my_memory.rb', line 29

def upload(tmx)
  body = [
    { key: :tmx, filename: 'import.tmx',
      content: tmx.to_xml, mime_type: 'application/xml' },
    { key: :private, value: 0 }
  ]
  response = http_client.post(UPLOAD_URL, body)
  log.debug(t('provider.share_response',
              response: response.body.inspect))
end