Module: Google::Language

Defined in:
lib/rtranslate/language.rb

Constant Summary collapse

Languages =
{
  'af' => 'AFRIKAANS',
  'sq' => 'ALBANIAN',
  'am' => 'AMHARIC',
  'ar' => 'ARABIC',
  'hy' => 'ARMENIAN',
  'az' => 'AZERBAIJANI',

  'eu' => 'BASQUE',
  'be' => 'BELARUSIAN',
  'bn' => 'BENGALI',
  'bh' => 'BIHARI',
  'bg' => 'BULGARIAN',
  'my' => 'BURMESE',

  'ca' => 'CATALAN',
  'chr' => 'CHEROKEE',
  'zh' => 'CHINESE',
  'zh-CN' => 'CHINESE_SIMPLIFIED',
  'zh-TW' => 'CHINESE_TRADITIONAL',
  'hr' => 'CROATIAN',
  'cs' => 'CZECH',

  'da' => 'DANISH',
  'dv' => 'DHIVEHI',
  'nl' => 'DUTCH',

  'en' => 'ENGLISH',
  'eo' => 'ESPERANTO',
  'et' => 'ESTONIAN',

  'tl' => 'FILIPINO',
  'fi' => 'FINNISH',
  'fr' => 'FRENCH',

  'gl' => 'GALICIAN',
  'ka' => 'GEORGIAN',
  'de' => 'GERMAN',
  'el' => 'GREEK',
  'gn' => 'GUARANI',
  'gu' => 'GUJARATI',

  'iw' => 'HEBREW',
  'hi' => 'HINDI',
  'hu' => 'HUNGARIAN',

  'is' => 'ICELANDIC',
  'id' => 'INDONESIAN',
  'iu' => 'INUKTITUT',
  'it' => 'ITALIAN',

  'ja' => 'JAPANESE',

  'kn' => 'KANNADA',
  'kk' => 'KAZAKH',
  'km' => 'KHMER',
  'ko' => 'KOREAN',
  'ku' => 'KURDISH',
  'ky' => 'KYRGYZ',

  'lo' => 'LAOTHIAN',
  'lv' => 'LATVIAN',
  'lt' => 'LITHUANIAN',

  'mk' => 'MACEDONIAN',
  'ms' => 'MALAY',
  'ml' => 'MALAYALAM',
  'mt' => 'MALTESE',
  'mr' => 'MARATHI',
  'mn' => 'MONGOLIAN',

  'ne' => 'NEPALI',
  'no' => 'NORWEGIAN',

  'or' => 'ORIYA',

  'ps' => 'PASHTO',
  'fa' => 'PERSIAN',
  'pl' => 'POLISH',
  'pt-PT' => 'PORTUGUESE',
  'pa' => 'PUNJABI',

  'ro' => 'ROMANIAN',
  'ru' => 'RUSSIAN',

  'sa' => 'SANSKRIT',
  'sr' => 'SERBIAN',
  'sd' => 'SINDHI',
  'si' => 'SINHALESE',
  'sk' => 'SLOVAK',
  'sl' => 'SLOVENIAN',
  'es' => 'SPANISH',
  'sw' => 'SWAHILI',
  'sv' => 'SWEDISH',

  'tg' => 'TAJIK',
  'ta' => 'TAMIL',
  'tl' => 'TAGALOG',
  'te' => 'TELUGU',
  'th' => 'THAI',
  'bo' => 'TIBETAN',
  'tr' => 'TURKISH',

  'uk' => 'UKRAINIAN',
  'ur' => 'URDU',
  'uz' => 'UZBEK',
  'ug' => 'UIGHUR',

  'vi' => 'VIETNAMESE',

  '' => 'UNKNOWN'
}

Class Method Summary collapse

Class Method Details

.abbrev(language) ⇒ Object

get the abbrev of the language



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rtranslate/language.rb', line 127

def abbrev(language)
  if supported?(language)
    if Languages.key?(language)
      language
    else
      language.upcase!
      Languages.each do |k,v|
        if v == language
          return k
        end
      end
    end
  else
    nil
  end
end

.supported?(language) ⇒ Boolean

judge whether the language is supported by google translate

Returns:

  • (Boolean)


117
118
119
120
121
122
123
# File 'lib/rtranslate/language.rb', line 117

def supported?(language)
  if Languages.key?(language) || Languages.value?(language.upcase)
    true
  else
    false
  end
end