Module: C3po::Translator

Included in:
C3po
Defined in:
lib/c3po.rb,
lib/c3po/translator.rb,
lib/c3po/translator/bing.rb,
lib/c3po/translator/google.rb,
lib/c3po/translator/result.rb,
lib/c3po/translator/configuration.rb

Defined Under Namespace

Classes: Bing, Configuration, Google, Result

Instance Method Summary collapse

Instance Method Details

#isString

Identify language.

Examples:

translator = C3po.new('translate')
translator.is

Returns:

  • (String)

    the identified language

Since:

  • 0.0.1



50
51
52
# File 'lib/c3po/translator.rb', line 50

def is
  @result.language ||= fetch @adaptor.build_detect_query
end

#is?(language) ⇒ Boolean

Check language.

Examples:

translator = C3po.new('translate')
translator.is? :fr

Parameters:

  • language (Symbol)

    to check

Returns:

  • (Boolean)

Since:

  • 0.0.1



66
67
68
# File 'lib/c3po/translator.rb', line 66

def is?(language)
  language.to_s == is
end

#languagesArray

Grab languages list from provider.

Examples:

translator = C3po.new('translate')
translator.languages

Returns:

  • (Array)

    the languages list

Since:

  • 0.0.1



36
37
38
# File 'lib/c3po/translator.rb', line 36

def languages
  @result.languages ||= fetch @adaptor.build_languages_query
end

#translate(from, to) ⇒ String

Translate a string.

Examples:

translator = C3po.new('translate')
translator.translate(:en, :fr)

Parameters:

  • language (Symbol)

    to translate from

  • language (Symbol)

    to translate to

Returns:

  • (String)

    the translated string

Since:

  • 0.0.1



18
19
20
21
22
23
24
# File 'lib/c3po/translator.rb', line 18

def translate(from, to)
  if @result.send(to)
    @result.send(to)
  else
    @result.send("#{to}=", fetch(@adaptor.build_query(from, to)))
  end
end