class Rufregle

Rufregle is a client api for translations it uses as default {FreeGoogle::Translator}

Attributes

translator[W]

Public Class Methods

new() click to toggle source
# File lib/rufregle.rb, line 9
def initialize()
  @translator = FreeGoogle::Factory.create()
end

Public Instance Methods

all_present?(params) click to toggle source
# File lib/rufregle.rb, line 31
def all_present?(params)
  params.each {|val| return false if val.nil? || val.empty? }
  return true
end
translate(text, from, to) click to toggle source

Return a translated text of a given text from language to another language

See language codes on {sites.google.com/site/tomihasa/google-language-codes}

@param text [String] Text to be translated. @param from [String] Language code of text @param to [String] Language code to be translate @raise Error unless all params informed @return [Hash] translated text and the original text from.

Example:
{ translated: "Ola mundo", original: "Hello word" }
# File lib/rufregle.rb, line 26
def translate(text, from, to)
  raise 'Rufregle: All params must be informed' unless all_present?([text, from, to])
  @translator.translate(text, from, to)
end