Sha256: 960a91a717cf2487d7ed602a2d6d7733a3bd9cbfb50930fc0048c3059366cc0e

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

module GoogleAjax
  module Language
    LANGUAGE_VERSION = 1.0
    def self.get(method, query, args)
      args = { :v => LANGUAGE_VERSION }.merge(args)
      GoogleAjax::get(:language, method, query, args)
    end
    
    # will return the language code that describes the language of the given text
    def self.detect(query, args = {})
      self.get(:detect, query, args)
    end
    
    # will return translated text for the given text supplied, matching the destination language.
    def self.translate(query, source, destination, args = {})
      args = { :langpair => "#{source}%7C#{destination}"}.merge(args)
      self.get(:translate, query, args)
    end
    
    class Language < Base
      def name
        (@@lang_cache ||= LANGUAGES.invert)[self.language]
      end
    end
    
    class Translation < Base
    end
    
    LANGUAGES =
    {
      'ARABIC' => 'ar',
      'BULGARIAN' => 'bg',
      'CATALAN' => 'ca',
      'CHINESE' => 'zh',
      'CHINESE_SIMPLIFIED' => 'zh-CN',
      'CHINESE_TRADITIONAL' => 'zh-TW',
      'CROATIAN' => 'hr',
      'CZECH' => 'cs',
      'DANISH' => 'da',
      'DUTCH'=> 'nl',
      'ENGLISH' => 'en',
      'ESTONIAN' => 'et',
      'FILIPINO' => 'tl',
      'FINISH' => 'fi',
      'FRENCH' => 'fr',
      'GERMAN' => 'de',
      'GREK' => 'el',
      'HEBREW' => 'iw',
      'HINDI' => 'hi',
      'HUNGARIAN' => 'hu',
      'INDONESIAN' => 'id',
      'ITALIAN' => 'it',
      'JAPANESE' => 'ja',
      'KOREAN' => 'ko',
      'LATVIAN' => 'lv',
      'LITHUANIAN' => 'lt',
      'NORWEGIAN' => 'no',
      'PERSIAN' => 'fa',
      'POLISH' => 'pl',
      'PORTUGUESE' => 'pt-PT',
      'ROMANIAN' => 'ro',
      'RUSIAN' => 'ru',
      'SERBIAN' => 'sr',
      'SLOVAK' => 'sk',
      'SLOVENIAN' => 'sl',
      'SPANISH' => 'es',
      'SWEDISH' => 'sv',
      'THAI' => 'th',
      'TURKISH' => 'tr',
      'UKRAINIAN' => 'uk',
      'VIETNAMESE' => 'vi',
      'UNKNOWN' => ''
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
googleajax-0.2.0 lib/googleajax/language.rb