Class: Translatomatic::Provider::MyMemory
- Defined in:
- lib/translatomatic/provider/my_memory.rb
Overview
Interface to the MyMemory translation API
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MyMemory
constructor
Create a new MyMemory provider instance.
-
#languages ⇒ Array<String>
A list of languages supported by this provider.
-
#upload(tmx) ⇒ void
Upload a set of translations to MyMemory.
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( = {}) super() @key = [:mymemory_api_key] || ENV['MYMEMORY_API_KEY'] @email = [:mymemory_email] || ENV['MYMEMORY_EMAIL'] @query_options = {} @query_options[:de] = @email if @email @query_options.merge!(key: @key) if @key end |
Instance Method Details
#languages ⇒ Array<String>
Returns 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
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 |