class Translatomatic::Provider::Frengly
Interface to the Frengly
translation API @see www.frengly.com/api
Constants
- URL
Public Class Methods
new(options = {})
click to toggle source
Create a new Frengly
provider instance
Calls superclass method
Translatomatic::Provider::Base::new
# File lib/translatomatic/provider/frengly.rb, line 16 def initialize(options = {}) super(options) @key = options[:frengly_api_key] || ENV['FRENGLY_API_KEY'] # optional @email = options[:frengly_email] @password = options[:frengly_password] raise t('provider.email_required') unless @email raise t('provider.password_required') unless @password end
Public Instance Methods
languages()
click to toggle source
(see Base#languages
)
# File lib/translatomatic/provider/frengly.rb, line 26 def languages %w[en fr de es pt it nl tl fi el iw pl ru sv] end
Private Instance Methods
fetch_translations(string, from, to)
click to toggle source
# File lib/translatomatic/provider/frengly.rb, line 38 def fetch_translations(string, from, to) body = { src: from.language, dest: to.language, text: string, email: @email, password: @password, premiumkey: @key }.to_json # TODO: work out what the response looks like response = http_client.post(URL, body, content_type: 'application/json') data = JSON.parse(response.body) add_translations(string, data['text']) end
perform_translate(strings, from, to)
click to toggle source
# File lib/translatomatic/provider/frengly.rb, line 34 def perform_translate(strings, from, to) perform_fetch_translations(URL, strings, from, to) end