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



46
47
48
# File 'lib/c3po/translator.rb', line 46

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



62
63
64
# File 'lib/c3po/translator.rb', line 62

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



32
33
34
# File 'lib/c3po/translator.rb', line 32

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
# File 'lib/c3po/translator.rb', line 18

def translate(from, to)
  @result.translation ||= fetch @adaptor.build_query(from, to)
end